错误:由于对象的当前状态,操作无效

时间:2013-06-19 12:45:45

标签: vb.net system.data.sqlite

我有这样的代码

Private con New SQLiteConnection("Data Source=" & FileName & ";Version=3;")

    Private Sub RemovePersonFromTable(ByVal tableName As String, ByVal index As Integer)
        Dim trans As SQLiteTransaction

        Dim SQL As String = "DELETE FROM " & tableName & " WHERE ID = " & index 

        Dim cmd As New SQLiteCommand(SQL)

        cmd.Connection = con

        trans = con.BeginTransaction()

        Dim retval As Integer = 0

        Try
            retval = cmd.ExecuteNonQuery()
        Catch ex As Exception
            trans.Rollback()
            ErrorMessage("Failed to store standard")
        Finally
            trans.Commit()
            cmd.Dispose()

        End Try
 End Sub

当我执行程序trans = con.BeginTransaction()时,我遇到Operation is not valid due to the current state of the object.错误。可以给我一个建议来解决这个问题吗?我在类构造函数中打开了连接

0 个答案:

没有答案