c#操作sqlite

释放双眼,带上耳机,听听看~!

一、添加选中dll引用如下图

c#操作sqlite

二、下载一个sqlite建表建库工具sqlitedatabasebrowser如下图

c#操作sqlite

三、使用sqlitedatabasebrowser建库建表

c#操作sqlite

四、插入表数据如下图

c#操作sqlite

四、连接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

 

 

给TA打赏
共{{data.count}}人
人已打赏
安全技术

详解Node.js API系列 Crypto加密模块(2) Hmac

2021-12-21 16:36:11

安全技术

从零搭建自己的SpringBoot后台框架(二十三)

2022-1-12 12:36:11

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索