C# - Sqlite3 实践

准备工作:

1. 从nuget下载Sqlite3相关库

2. 准备数据库.

2.1 搜索SqlExercise Wiki,进入并选择The Hospital范例. 复制Sql语句,保存为hopistal.sql. 或者使用其他数据库

2.2 启动Sqlite3, 输入 >> .read hopistal.sql  输入命令>>.save hopital.db  生成Hospital数据库

 

        string connString = @"Data Source=D:\sqlite-tools-win32-x86-3180000\hospital.db;Version=3";
            SQLiteConnection con = new SQLiteConnection(connString);
            con.Open();
            
            string query = @"SELECT * FROM Stay";

            SQLiteDataAdapter da = new SQLiteDataAdapter(query, con);
            DataSet ds = new DataSet();
            da.Fill(ds, "hello");
            
            this.dataGrid1.DataSource = ds.Tables[0];
            //this.dataGrid1.DataMember = "hello";
            con.Close();

 

1.  首先需要引用Sqlite3的.netframe驱动System.Data.SQLite.dll

2.      设计数据库并编入数据,假设这里存在一个Stay的数据表

3.      调用显示代码,结果如下

 

posted @ 2017-06-04 10:06  勿在浮沙筑高台  阅读(3537)  评论(0编辑  收藏  举报