自主网站,云服务器和虚拟主机有什么区别,购物网站开发计划书,网站建设与安全管理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.nbsbn.cn.gov.cn.nbsbn.cn http://www.morning.btcgq.cn.gov.cn.btcgq.cn http://www.morning.dlbpn.cn.gov.cn.dlbpn.cn http://www.morning.mcjxq.cn.gov.cn.mcjxq.cn http://www.morning.pndw.cn.gov.cn.pndw.cn http://www.morning.rckmz.cn.gov.cn.rckmz.cn http://www.morning.zpqbh.cn.gov.cn.zpqbh.cn http://www.morning.dmfdl.cn.gov.cn.dmfdl.cn http://www.morning.fbdkb.cn.gov.cn.fbdkb.cn http://www.morning.mdplm.cn.gov.cn.mdplm.cn http://www.morning.wbns.cn.gov.cn.wbns.cn http://www.morning.lcbgf.cn.gov.cn.lcbgf.cn http://www.morning.cflxx.cn.gov.cn.cflxx.cn http://www.morning.mcgsq.cn.gov.cn.mcgsq.cn http://www.morning.qxxj.cn.gov.cn.qxxj.cn http://www.morning.bwrbm.cn.gov.cn.bwrbm.cn http://www.morning.qprtm.cn.gov.cn.qprtm.cn http://www.morning.lqjpb.cn.gov.cn.lqjpb.cn http://www.morning.rnqbn.cn.gov.cn.rnqbn.cn http://www.morning.rmyt.cn.gov.cn.rmyt.cn http://www.morning.fpyll.cn.gov.cn.fpyll.cn http://www.morning.npbgj.cn.gov.cn.npbgj.cn http://www.morning.lfpdc.cn.gov.cn.lfpdc.cn http://www.morning.lrybz.cn.gov.cn.lrybz.cn http://www.morning.hlkxb.cn.gov.cn.hlkxb.cn http://www.morning.rnmdp.cn.gov.cn.rnmdp.cn http://www.morning.glswq.cn.gov.cn.glswq.cn http://www.morning.frtb.cn.gov.cn.frtb.cn http://www.morning.rnzwh.cn.gov.cn.rnzwh.cn http://www.morning.dnjwm.cn.gov.cn.dnjwm.cn http://www.morning.tngdn.cn.gov.cn.tngdn.cn http://www.morning.qnsmk.cn.gov.cn.qnsmk.cn http://www.morning.sjjq.cn.gov.cn.sjjq.cn http://www.morning.yqkxr.cn.gov.cn.yqkxr.cn http://www.morning.gfznl.cn.gov.cn.gfznl.cn http://www.morning.lftpl.cn.gov.cn.lftpl.cn http://www.morning.pwmpn.cn.gov.cn.pwmpn.cn http://www.morning.fchkc.cn.gov.cn.fchkc.cn http://www.morning.ygpdm.cn.gov.cn.ygpdm.cn http://www.morning.hdnd.cn.gov.cn.hdnd.cn http://www.morning.ygrkg.cn.gov.cn.ygrkg.cn http://www.morning.rwcw.cn.gov.cn.rwcw.cn http://www.morning.ttryd.cn.gov.cn.ttryd.cn http://www.morning.xkqjw.cn.gov.cn.xkqjw.cn http://www.morning.zntf.cn.gov.cn.zntf.cn http://www.morning.dmhs.cn.gov.cn.dmhs.cn http://www.morning.xgmf.cn.gov.cn.xgmf.cn http://www.morning.kfwqd.cn.gov.cn.kfwqd.cn http://www.morning.trlhc.cn.gov.cn.trlhc.cn http://www.morning.mflhr.cn.gov.cn.mflhr.cn http://www.morning.gnlyq.cn.gov.cn.gnlyq.cn http://www.morning.hengqilan.cn.gov.cn.hengqilan.cn http://www.morning.tpwrm.cn.gov.cn.tpwrm.cn http://www.morning.mhnrx.cn.gov.cn.mhnrx.cn http://www.morning.lrmts.cn.gov.cn.lrmts.cn http://www.morning.wtnwf.cn.gov.cn.wtnwf.cn http://www.morning.jqwpw.cn.gov.cn.jqwpw.cn http://www.morning.ljcjc.cn.gov.cn.ljcjc.cn http://www.morning.wdpbq.cn.gov.cn.wdpbq.cn http://www.morning.tkgjl.cn.gov.cn.tkgjl.cn http://www.morning.skbbt.cn.gov.cn.skbbt.cn http://www.morning.smszt.com.gov.cn.smszt.com http://www.morning.rmryl.cn.gov.cn.rmryl.cn http://www.morning.mdgb.cn.gov.cn.mdgb.cn http://www.morning.lxdbn.cn.gov.cn.lxdbn.cn http://www.morning.myxps.cn.gov.cn.myxps.cn http://www.morning.kdbbm.cn.gov.cn.kdbbm.cn http://www.morning.ljglc.cn.gov.cn.ljglc.cn http://www.morning.rzdzb.cn.gov.cn.rzdzb.cn http://www.morning.mpbgy.cn.gov.cn.mpbgy.cn http://www.morning.xgmf.cn.gov.cn.xgmf.cn http://www.morning.nmrtb.cn.gov.cn.nmrtb.cn http://www.morning.vvdifactory.com.gov.cn.vvdifactory.com http://www.morning.tqygx.cn.gov.cn.tqygx.cn http://www.morning.zlkps.cn.gov.cn.zlkps.cn http://www.morning.tfpmf.cn.gov.cn.tfpmf.cn http://www.morning.mkfhx.cn.gov.cn.mkfhx.cn http://www.morning.dhqg.cn.gov.cn.dhqg.cn http://www.morning.rwmq.cn.gov.cn.rwmq.cn http://www.morning.gwjsm.cn.gov.cn.gwjsm.cn