2015-03-25 96 views
3

我想讀本地SQLite數據庫中的表Condition的所有數據。但是我得到這個錯誤:SQL邏輯錯誤或缺失數據庫沒有這樣的表

SQL logic error or missing database no such table

數據庫位於與調用它的文件相同的目錄中。

這是我的代碼:

SQLiteConnection m_dbConnection = new SQLiteConnection("Data Source=myDatabase.sqlite;Version=3;"); 
m_dbConnection.Open(); 

try 
{ 
    string sql = "select * from Condition"; 
    SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection); 

    SQLiteDataReader reader = command.ExecuteReader(); 

    while (reader.Read()) 
     Console.WriteLine("Name: " + reader["name"] + "\tScore: " + reader["id"]); 

    Console.ReadLine(); 
    return null; 
} 
catch (Exception exc) 
{ 
    return null; 
} 
finally 
{ 
    m_dbConnection.Close(); 
} 
+0

這是你使用數據庫文件的確切路徑嗎? – horHAY 2015-03-25 08:12:35

+0

我建議你爲你的數據源嘗試一個完全合格的路徑(比如'C:/whatever/myDatabase.sqlite'來檢查你的代碼是否真的找到了數據庫文件,你的語句和調用它的*文件* 「聽起來對我來說很可疑 - 你如何運行你的代碼? – 2015-03-25 08:18:17

回答

4

我已經使用絕對路徑,而不是相對路徑解決了該問題。 感謝Eternal21 https://stackoverflow.com/a/20083762/3483812

+0

我想在上面的註釋中說,當你運行該程序的目錄變成項目/斌/調試,我猜你是在解決方案的目錄中文件? – horHAY 2015-03-25 08:22:53

3

數據庫應位於您的bin文件夾中,或者指定.sqlite文件的絕對路徑。

相關問題