SQLite Query无法正常工作 - 无法加载数据表

时间:2014-02-15 23:38:38

标签: vb.net sqlite

我正在尝试编写一个查询我所拥有的sqlite db的函数。由于某种原因,它无法正常工作。以下是我正在使用的支持功能。我可以让它完美地添加表格。

    Private Sub GetSqlConnection()
        Me.SQLConnectionString = New SQLiteConnectionStringBuilder
        Me.SQLConnectionString.DataSource = Path.Combine(Application.StartupPath, "mydb.sqlite")
        Me.SQLConnectionString.Version = 3

        SQLConnection = New SQLiteConnection(Me.SQLConnectionString.ConnectionString)
    End Sub

    Private Sub Query(ByVal SQLString As String)
        Try
            Dim SQLiteDRObj As SQLiteDataReader
            Dim ResultsTableObj As DataTable = Nothing
            Dim ResultSet As DataSet = Nothing
            Dim SQLAdapter As SQLiteDataAdapter = Nothing

            Me.GetSqlConnection()
            SQLConnection.Open()
            SQLCommand = New SQLiteCommand(SQLConnection)
            SQLCommand.CommandText = SQLString

            SQLiteDRObj = SQLCommand.ExecuteReader()

            ResultsTableObj.Load(SQLiteDRObj)

            SQLiteDRObj.Close()
            SQLConnection.Close()
            SQLConnection.Dispose()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

object shows as filled http://josephberardi.com/stackoverflow/objfilled.png

object shows as filled http://josephberardi.com/stackoverflow/exception.png

1 个答案:

答案 0 :(得分:1)

调用Load方法

时,

ResultsTableObj为Nothing

将此行更改为

Private Sub Query(ByVal SQLString As String)
    Try
       ....
       Dim ResultsTableObj As DataTable = New DataTable()
       ....