1000字范文,内容丰富有趣,学习的好帮手!
1000字范文 > 怎么连接并建立一个类库 – 数据库 – 前端

怎么连接并建立一个类库 – 数据库 – 前端

时间:2023-03-28 21:54:55

相关推荐

怎么连接并建立一个类库 – 数据库 – 前端

一、关于SQLite : System.Data.SQLite 是一个原始 SQLite 的加强版。它不需要链接 .NET Runtime,因此可脱离 .NET 独立发布,它内嵌了一个完整的 2.0 引擎,为开发提供了完整的支持。

二、在C#中使用SQLite1. 添加引用: System.Data.SQLite.DLL 。

2. 创建数据库文件: SQLiteConnection.CreateFile(fileName)

;3. 连接数据库: var connection = new SQLiteConnection(connectionString);connectionString 中包含了数据库的一些配置信息,比如数据库文件路径,数据库密码等,可用 SQLiteConnectionStringBuilder 来创建 connectionString,当然也有其他方法,都很简单。

4. 从数据库读取数据。三、代码:view sourceprint?// 注意此处 using 。

using System;using System.Data.SQLite;using System.Text;namespace ConsoleApplication{public class SQLiteTester{public static void Test(){// 1.创建一个数据库文件。

var databaseFileName = "D:/test.db3";SQLiteConnection.CreateFile(databaseFileName)

;// 2.创建数据库连接。

var connectionString = new SQLiteConnectionStringBuilder{DataSource = databaseFileName,Password = "xxxxxx" // 此处假设数据库密码为: xxxxxx。};// 当然也可以直接: var connection = new SQLiteConnection("data source=" + databaseFileName + ";password=" + Password)

;using (var connection = new SQLiteConnection(connectionString.ToString())){// 3.打开连接。connection.Open();

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。