Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Error Prepare require an open and avaible connection.

$
0
0
Hello. I have a problem and can't figure out :( . Here is the code:
Private Sub FButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FButton.Click
        If conn.State = ConnectionState.Closed Then
            conn.Open()
        End If
        If DatabaseGetMAX("ID", LunaG & AnulG) = -1 Then
            MsgBox("Introduce ceva informatii in tabel inainte de a o incheia!")
        Else
            Dim V As Integer = MsgBox("Sigur doresti sa inchizi luna?", MsgBoxStyle.YesNo, "")
            If V = DialogResult.Yes Then
                DatabaseActivitateUpdateActvCell(0, LunaG, AnulG)
                If conn.State = ConnectionState.Open Or ConnectionState.Broken Or ConnectionState.Connecting Or ConnectionState.Fetching Then
                    conn.Close()
                    MsgBox("Conn.CLOSE")
                End If
                If conn.State = ConnectionState.Closed Then
                    MsgBox("Conn.OPEN")
                    conn.Open()
                End If
                MsgBox("asdasd")
                DatabaseActivitateUpdateMoneys(AdunareTotal(LunaG & AnulG, "LEI") & " LEI", AdunareTotal(LunaG & AnulG, "EURO") & " EURO", AdunareTotal(LunaG & AnulG, "DOLARI") & " DOLARI", LunaG, AnulG) 'Linia cu eroare
                MsgBox("sdasd")
                Dim LV As Integer = DatabaseGetINT("Valoare", "General", "Nume", "LunaActiva")
                DatabaseUpdateCellINT("Valoare", LV - 1, "General", "Nume", "LunaActiva")
                DatabaseDropTable(LunaG & AnulG & "Ada")
                Me.Close()
                VForm.Close()
                InitializeForm1(0)
                InitializeForm1()
            End If
        End If
        conn.Close()
    End Sub

'----- MyModule
Function DatabaseActivitateUpdateMoneys(ByVal SumaL As String, ByVal SumaE As String, ByVal SumaD As String, ByVal Luna As String, ByVal Anul As String)
        Dim cmd As SqlCeCommand = conn.CreateCommand()
        Try
            cmd.CommandText = "UPDATE Activitate SET SumaL='" & SumaL & "', SumaE='" & SumaE & "', SumaD='" & SumaD & "' WHERE Luna='" & Luna & "' AND Anul='" & Anul & "'"
            cmd.Prepare()
            cmd.ExecuteNonQuery()
        Catch ex As Exception
            MsgBox(ex.Message & "Eroare4")
        End Try
        Return 1
    End Function



Also I have errors and to the next lines:
Dim LV As Integer = DatabaseGetINT("Valoare", "General", "Nume", "LunaActiva")
                DatabaseUpdateCellINT("Valoare", LV - 1, "General", "Nume", "LunaActiva")
                DatabaseDropTable(LunaG & AnulG & "Ada")


Same error to all, error:

Quote

Prepare require an open and avaible connection. The connection's current state is closed. Eroare 4

Viewing all articles
Browse latest Browse all 51036

Trending Articles