当前位置: 首页> 文旅> 旅游 > 2023年免费进入b站的原因_如何建立网站视频_友点企业网站管理系统_短视频代运营公司

2023年免费进入b站的原因_如何建立网站视频_友点企业网站管理系统_短视频代运营公司

时间:2025/7/12 6:37:51来源:https://blog.csdn.net/ljygood2/article/details/144112672 浏览次数:0次
2023年免费进入b站的原因_如何建立网站视频_友点企业网站管理系统_短视频代运营公司

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};Version=3;")){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);}}

程序运行结果

关键字:2023年免费进入b站的原因_如何建立网站视频_友点企业网站管理系统_短视频代运营公司

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: