2017-06-27 44 views
0

我正在使用xamarin創建一個Android應用程序。我有一個預先存在的SQLite數據庫,我正在加載到設備上。SQLite-net查詢不返回行

我正在使用Frank Kreuger的Sqlite-Net nuget軟件包。

在數據庫中,我有一個表名列表,它目前有一行。

我正在使用Query方法來嘗試並檢索該行。但它沒有被退回。

我打開連接

db = new SQLiteConnection(FileAccessHelper.GetDBLocation(dbName)); 

這給我位於 DatabasePath 「/data/user/0/readdb.readdb/files/packinglists.sqlite」

我我的數據庫的連接然後嘗試並檢索行

try 
{ 
    List<tabledefs.Lists> myLists = db.Query<tabledefs.Lists>("select * from Lists"); 
    foreach (tabledefs.Lists list in myLists) 
    { 
     listNames[counter++] = list.ListName; 
    } 
}catch (Exception e) 
{ 
    //do something 
} 

即使我可以手動打開數據庫並查詢數據,調用也不會返回任何行。

回答

0

在移動設備上並沒有真正擺弄SQLite,但很確定這個過程與Web服務相同。

// Location of the Database 
string connectionString; 

// Use a "Using" instead of a try-catch-finally statement for automatic Dispose 
using (var db = new SQLiteConnection (connectionString)) 
{ 
    // Use a Data Adapter and CommandBuilder to initiate and receive the data from the db. 
    SQLiteDataAdapter myDataAdapter = new SQLiteDataAdapter ("select * from Lists", connectionString); 
    SQLiteCommandBuilder myCommand = new SQLiteCommandBuilder (myDataAdapter); 

    // Create a Data Table to Store the db 
    // Open the Database 
    // Fill the Data Table from the Adapter that received the db 
    DataTable newDataTable = new DataTable; 
    db.Open(); 
    myDataAdapter.Fill (newDataTable); 

    // Now if you run through each row and use "row.ItemArray[]" you can get 
    // the specific data type in each value. 
    foreach (DataRow row in newDataTable.Rows) 
    { 
     "Your Rows Here" 
    } 
} 

應該給你的每一行單獨所有你需要做的就是投行的各項指標,以正確的值類型,以獲得列的值。