天天看點

在c#中使用sqlite的兩個注意點

在C#中使用sqlite,遇到了找不到SQLite.Interop.dll。窗體設計器不能打開。

懷疑過代碼是否支援x64,還是其他mode。換了很多sqlite版本,包括nuget.

Install-Package linq2db.SQLite      
發現是vs2012對exception的要求很高。如果在視窗的執行個體化過程中使用資料庫,就一定要做try catch 操作。      
    public partial class IssuerCert : UserControl
    {
        public IssuerCert()
        {
            dRow = _sql.conn();  
        }
    }      
    public DataTable connt()
    {
           try
            {
                conn = new SQLiteConnection(dbPath);
                conn.Open();
            }
            catch
            {
                return data;
            }
      
}      
最後sqlite支援SQLiteDataAdapter adapter = new SQLiteDataAdapter(cmd);  adapter.Fill(DataTable  data); DataTable       
可以直接從sqlite獲得整張表。使用c#的api對表格操作。