2009-07-23 23 views
0

我用這個代碼和SQLite說:「數據源不能爲空。用途:內存:打開一個內存數據庫」適配器不使用SQLite C#加載任何

這裏是我的代碼

string dbfile = new System.IO.FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).DirectoryName + "\\m23.db"; 

     string sql; 

     DateTime dt = DateTime.Now; 
     SQLiteConnection connection = new SQLiteConnection("datasource="+ dbfile); 

     SQLiteDataAdapter adapter = new SQLiteDataAdapter("select * from p_posts", connection); 
     DataSet data = new DataSet(); 
     adapter.Fill(data); // <<< here i get the error 

     SQLiteCommand cmd = new SQLiteCommand(); 
     cmd.CommandType = CommandType.TableDirect; 
     cmd.Connection = connection; 

     connection.Open(); 

任何幫助, 乾杯!

回答

1

使用

SQLiteConnection connection = new SQLiteConnection("Data Source=" + dbfile); 

examples我見過使用 「數據源」,而不是 「數據源」 嘗試。

+0

它的工作原理! ,但現在它說我的桌子存在o.O – Aviatrix 2009-07-23 14:25:48

0

爲了避免這樣的參數語法問題,你也可以考慮用SQLiteConnectionStringBuilder

SQLiteConnectionStringBuilder con = new SQLiteConnectionStringBuilder(); 
con.DataSource = dbfile; 
相關問題