0

私はvb.netでデータベースを扱うクラスを持っています

したがって、これは正しいと思いますが、プログラムがテーブルにアクセスするフォームにデータを正しく挿入しないことがありますプログラム そして、私は再び挿入することができます...

この理由は何でしょうか?

私は現在、実行を処理するためにこの命令を持っています

    con = New OdbcConnection
    con.ConnectionString = "Dsn=A;uid=sa;pwd=A;"
    con.Open()
    Dim cmd As New OdbcCommand(SQL, con)
    dr = cmd.ExecuteReader
    cmd.Connection.Close()
    cmd.Connection.Dispose()
    cmd.Connection = Nothing
    cmd.Parameters.Clear()
    cmd.Dispose()
    cmd = Nothing
    con.Close()
    con.Dispose()

私は持っている

Public Shared Function GetDataReader(ByVal SQL As String) As OdbcDataReader
        Dim dr As OdbcDataReader
        Try
            con = New OdbcConnection
            con.ConnectionString = "Dsn=A;uid=sa;pwd=A;"
            con.Open()
            Dim cmd As New OdbcCommand(SQL, con)
            dr = cmd.ExecuteReader
            cmd.Connection.Close()
            cmd.Connection.Dispose()
            cmd.Connection = Nothing
            cmd.Parameters.Clear()
            cmd.Dispose()
            cmd = Nothing
            con.Close()
            con.Dispose()
            Return dr
        Catch ex As Exception
            MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If (con.State = System.Data.ConnectionState.Open) Then
                con.Close()
                con.Dispose()
            End If
        End Try
        dr = Nothing
        Return dr
    End Function


Public Shared Function GetDataTable(ByVal SQL As String) As DataTable
        Dim table As New DataTable

        Try
            con = New OdbcConnection
            con.ConnectionString = "Dsn=A;uid=sa;pwd=A;"
            con.Open()
            Dim cmd As New OdbcCommand(SQL, con)

            Dim da As New OdbcDataAdapter(cmd)
            da.Fill(table)
            cmd.Connection.Close()
            cmd.Connection.Dispose()
            cmd.Connection = Nothing
            cmd.Parameters.Clear()
            cmd.Dispose()
            cmd = Nothing
            con.Close()
            con.Dispose()
            Return table
        Catch ex As Exception
            MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If (con.State = System.Data.ConnectionState.Open) Then
                con.Close()
                con.Dispose()
            End If
        End Try
        Return table
    End Function



    Public Shared Sub ExecuteQuery(ByVal SQL As String)
        Try
            con = New OdbcConnection
            con.ConnectionString = "Dsn=A;uid=sa;pwd=A;"
            con.Open()
            Dim cmd As New OdbcCommand(SQL, con)
            cmd.ExecuteNonQuery()
            cmd.Connection.Close()
            cmd.Connection.Dispose()
            cmd.Connection = Nothing
            cmd.Parameters.Clear()
            cmd.Dispose()
            cmd = Nothing
            con.Close()
            con.Dispose()
        Catch ex As Exception
            MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If (con.State = System.Data.ConnectionState.Open) Then
                con.Close()
                con.Dispose()
            End If
        End Try
    End Sub
End Class
4

0 に答える 0