2012-02-22 61 views
0

我有一個SQLite數據庫,我打算查詢RecordID字段中的最大值。當我在SQLite中運行它時,這個查詢是有效的,但我無法讓VB返回值,我做了什麼錯誤?從Sqlite DB返回最大值

Dim getMaxRecID As String = "SELECT MAX(RecordID) FROM String" 
Using cmd1 As New SQLiteCommand(getMaxRecID, pConn) 
     cmd1.CommandType = CommandType.Text 
     Dim IDresults As Integer 

     Try 
      IDresults = cmd1.ExecuteNonQuery() 
     Catch ex As Exception 

      Throw 
     End Try 

連接正確打開數據庫,並顯示它也是開放的。沒有錯誤,只是IDresults每次都返回0。

感謝您的任何幫助。

回答

0

這解決了這個問題....

    Dim ds2 As New DataSet 
        Dim da2 As SQLiteDataAdapter 

        Try 
         da2 = New SQLiteDataAdapter(getMaxRecID, pConn) 
         da2.Fill(ds2) 

         IDresults = ds2.Tables(0).Rows(0).Item(0)