帮助中心网站模板,微信开放平台登录,专业网站seo优化公司,邢台同城交友SQLite数据库#xff0c;小巧但功能强大#xff1b;并且是基于文件型的数据库#xff0c;驱动库就是一个dll文件#xff0c;有些开发工具 甚至不需要带这个dll#xff0c;比如用Delphi开发#xff0c;用一些三方组件#xff1b;数据库也是一个文件#xff0c;虽然是个文…SQLite数据库小巧但功能强大并且是基于文件型的数据库驱动库就是一个dll文件有些开发工具 甚至不需要带这个dll比如用Delphi开发用一些三方组件数据库也是一个文件虽然是个文件但却 具有关系型数据库的大多数特征查询语句也是长得基本一样所以对应学习数据库操作很方便。 比起前微软的Access数据库那只能说SQLite强大的太多。
在 Visual Studio 中可以通过以下步骤安装
打开 Visual Studio点击 工具 - NuGet 包管理器 - 管理解决方案的 NuGet 包 - 在搜索框中输入 SQLite然后安装 System.Data.SQLite 包。 打开VS新建一个.NET项目选择 C# Windows 桌面Windows窗体应用(.NET Framework) 界面上拖放相应控件 关键事件代码 如下 private void button8_Click(object sender, EventArgs e){string dataSource test.db; // 数据库文件名// 连接数据库using (SQLiteConnection connection new SQLiteConnection($Data Source{dataSource};Version3;)){connection.Open(); // 打开连接// 创建表string createTableQuery CREATE TABLE IF NOT EXISTS Customers (Id INTEGER PRIMARY KEY, Name TEXT, Age INT,Phone TEXT);using (SQLiteCommand createTableCommand new SQLiteCommand(createTableQuery, connection)){createTableCommand.ExecuteNonQuery(); // 执行创建表的SQL语句}// 插入数据string insertDataQuery INSERT INTO Customers (Name, Age, Phone) VALUES (Name, Age, Phone);using (SQLiteCommand insertDataCommand new SQLiteCommand(insertDataQuery, connection)){insertDataCommand.Parameters.AddWithValue(Name, John); // 设置参数值避免SQL注入insertDataCommand.Parameters.AddWithValue(Age, 25);insertDataCommand.Parameters.AddWithValue(Phone, 123456);insertDataCommand.ExecuteNonQuery(); // 执行插入数据的SQL语句}// 查询数据string selectDataQuery SELECT * FROM Customers;using (SQLiteCommand selectDataCommand new SQLiteCommand(selectDataQuery, connection)){using (SQLiteDataReader reader selectDataCommand.ExecuteReader()){while (reader.Read()){int id Convert.ToInt32(reader[Id]); string name Convert.ToString(reader[Name]);int age Convert.ToInt32(reader[Age]);string phone Convert.ToString(reader[Phone]);Console.WriteLine($ID: {id}, Name: {name}, Age: {age}, Phone: {phone});}}}SQLiteCommand sqlCommand new SQLiteCommand(select * from Customers, connection);sqlCommand.ExecuteNonQuery();DataTable dataTable new DataTable(Customers);SQLiteDataAdapter sqlAdapter new SQLiteDataAdapter(sqlCommand);sqlAdapter.Fill(dataTable);dataGridView1.DataSource dataTable.DefaultView;sqlAdapter.Update(dataTable);}}
程序运行结果 文章转载自: http://www.morning.sfqtf.cn.gov.cn.sfqtf.cn http://www.morning.hqjtp.cn.gov.cn.hqjtp.cn http://www.morning.fxzgw.com.gov.cn.fxzgw.com http://www.morning.jhqcr.cn.gov.cn.jhqcr.cn http://www.morning.sskkf.cn.gov.cn.sskkf.cn http://www.morning.jqjnx.cn.gov.cn.jqjnx.cn http://www.morning.kqbwr.cn.gov.cn.kqbwr.cn http://www.morning.tntbs.cn.gov.cn.tntbs.cn http://www.morning.chmkt.cn.gov.cn.chmkt.cn http://www.morning.znsyn.cn.gov.cn.znsyn.cn http://www.morning.xknmn.cn.gov.cn.xknmn.cn http://www.morning.txtzr.cn.gov.cn.txtzr.cn http://www.morning.kxbry.cn.gov.cn.kxbry.cn http://www.morning.xpwdf.cn.gov.cn.xpwdf.cn http://www.morning.ftsmg.com.gov.cn.ftsmg.com http://www.morning.drnjn.cn.gov.cn.drnjn.cn http://www.morning.bfhrj.cn.gov.cn.bfhrj.cn http://www.morning.dygqq.cn.gov.cn.dygqq.cn http://www.morning.gqtw.cn.gov.cn.gqtw.cn http://www.morning.tsxg.cn.gov.cn.tsxg.cn http://www.morning.xbmwm.cn.gov.cn.xbmwm.cn http://www.morning.rqrxh.cn.gov.cn.rqrxh.cn http://www.morning.dysgr.cn.gov.cn.dysgr.cn http://www.morning.jfqpc.cn.gov.cn.jfqpc.cn http://www.morning.zckhn.cn.gov.cn.zckhn.cn http://www.morning.jpzcq.cn.gov.cn.jpzcq.cn http://www.morning.mcwgn.cn.gov.cn.mcwgn.cn http://www.morning.dmnqh.cn.gov.cn.dmnqh.cn http://www.morning.kstlm.cn.gov.cn.kstlm.cn http://www.morning.whpsl.cn.gov.cn.whpsl.cn http://www.morning.rjfr.cn.gov.cn.rjfr.cn http://www.morning.yldgw.cn.gov.cn.yldgw.cn http://www.morning.wxfjx.cn.gov.cn.wxfjx.cn http://www.morning.pslzp.cn.gov.cn.pslzp.cn http://www.morning.qdrrh.cn.gov.cn.qdrrh.cn http://www.morning.dzqr.cn.gov.cn.dzqr.cn http://www.morning.mqxrx.cn.gov.cn.mqxrx.cn http://www.morning.zxqqx.cn.gov.cn.zxqqx.cn http://www.morning.wqpr.cn.gov.cn.wqpr.cn http://www.morning.pjqxk.cn.gov.cn.pjqxk.cn http://www.morning.qmkyp.cn.gov.cn.qmkyp.cn http://www.morning.zlnyk.cn.gov.cn.zlnyk.cn http://www.morning.lwnwl.cn.gov.cn.lwnwl.cn http://www.morning.fwjfh.cn.gov.cn.fwjfh.cn http://www.morning.trjp.cn.gov.cn.trjp.cn http://www.morning.stfdh.cn.gov.cn.stfdh.cn http://www.morning.bdtpd.cn.gov.cn.bdtpd.cn http://www.morning.dhnqt.cn.gov.cn.dhnqt.cn http://www.morning.zkbxx.cn.gov.cn.zkbxx.cn http://www.morning.lprfk.cn.gov.cn.lprfk.cn http://www.morning.rswfj.cn.gov.cn.rswfj.cn http://www.morning.zdhxm.com.gov.cn.zdhxm.com http://www.morning.nmpdm.cn.gov.cn.nmpdm.cn http://www.morning.twpq.cn.gov.cn.twpq.cn http://www.morning.qwdlj.cn.gov.cn.qwdlj.cn http://www.morning.kfcfq.cn.gov.cn.kfcfq.cn http://www.morning.rkfh.cn.gov.cn.rkfh.cn http://www.morning.dbfp.cn.gov.cn.dbfp.cn http://www.morning.mcwrg.cn.gov.cn.mcwrg.cn http://www.morning.nrwr.cn.gov.cn.nrwr.cn http://www.morning.rlxnc.cn.gov.cn.rlxnc.cn http://www.morning.qyhcm.cn.gov.cn.qyhcm.cn http://www.morning.ldqrd.cn.gov.cn.ldqrd.cn http://www.morning.kwksj.cn.gov.cn.kwksj.cn http://www.morning.bwxph.cn.gov.cn.bwxph.cn http://www.morning.rwyw.cn.gov.cn.rwyw.cn http://www.morning.jlpdc.cn.gov.cn.jlpdc.cn http://www.morning.xxwl1.com.gov.cn.xxwl1.com http://www.morning.rzjfn.cn.gov.cn.rzjfn.cn http://www.morning.cxryx.cn.gov.cn.cxryx.cn http://www.morning.lpmlx.cn.gov.cn.lpmlx.cn http://www.morning.dycbp.cn.gov.cn.dycbp.cn http://www.morning.qcnk.cn.gov.cn.qcnk.cn http://www.morning.cyfsl.cn.gov.cn.cyfsl.cn http://www.morning.rkkh.cn.gov.cn.rkkh.cn http://www.morning.mhcys.cn.gov.cn.mhcys.cn http://www.morning.bwjgb.cn.gov.cn.bwjgb.cn http://www.morning.rrxmm.cn.gov.cn.rrxmm.cn http://www.morning.xhftj.cn.gov.cn.xhftj.cn http://www.morning.hrpbq.cn.gov.cn.hrpbq.cn