释放双眼,带上耳机,听听看~!
一、添加选中dll引用如下图
二、下载一个sqlite建表建库工具sqlitedatabasebrowser如下图
三、使用sqlitedatabasebrowser建库建表
四、插入表数据如下图
四、连接sqlite
1
2
3
4
5
6
7 1public SQLiteConnection GetCon()
2 {
3 readonly string DbFile=@"F:\project\net_mk_web\zkx_mk_web\zkx_mk_web\bin\text.db";
4 SQLiteConnection SQLCON = new SQLiteConnection("Data Source=" + DbFile + ";Version=3");
5 return SQLCON;
6 }
7
1
2
3
4
5
6
7
8
9
10
11 1 public SQLiteConnection open()
2 {
3 //SQLiteConnection.CreateFile(DbFile);
4 SQLiteConnection sqlcon = GetCon();
5 if(sqlcon.State!=ConnectionState.Open)
6 {
7 sqlcon.Open();
8 }
9 return sqlcon;
10 }
11
五、执行sqlite
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 1 public List<String> Execution()
2 {
3 List<string> data = new List<string>();
4 SQLiteConnection opencon = open();
5 using (SQLiteCommand sqlcommand = new SQLiteCommand("select * from user", opencon))
6 {
7 SQLiteDataReader sqlread = sqlcommand.ExecuteReader();
8 while (sqlread.Read())
9 {
10 data.Add(sqlread["username"].ToString());
11 }
12 }
13 return data;
14 }
15