2014-02-15 50 views
0

我想寫一個函數,查詢我有sqlite數據庫。出於某種原因,它無法正常工作。以下是我正在使用的支持功能。我可以把它添加到表格中。SQLite查詢不能正常工作 - 無法加載數據表

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

ResultsTableObj是沒有什麼,當你調用Load方法

更改此行

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

謝謝你的。我一直在強調。我知道這簡直是愚蠢的。 – joeb