1.数据库连接(常用连接方法,示例)

1). 添加引用: System.Data.SQLite.DLL 。
2). 打开或创建数据库文件: SQLiteConnection.CreateFile(fileName);
3). 连接数据库: var connection = new SQLiteConnection(connectionString);
connectionString 中包含了数据库的一些配置信息,比如数据库文件路径,数据库密码等,可用 SQLiteConnectionStringBuilder 来创建 connectionString
 1 string dbPath = Environment.CurrentDirectory + "/test.db";/*指定数据库路径 */
 2 using(SQLiteConnection conn = new SQLiteConnection("Data Source =" + dbPath))
 3  {
 4      conn.Open();
 5      DbCommand comm = conn.CreateCommand();
 6      comm.CommandText = "select * from customer";
 7      comm.CommandType = CommandType.Text;
 8      using (IDataReader reader = comm.ExecuteReader())
 9      {
10         while (reader.Read())
11         {
12           Response.Write(reader[0]);
13         }
14       }
15   }
View Code

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-27
  • 2022-12-23
  • 2021-07-01
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-16
  • 2022-12-23
  • 2021-06-13
相关资源
相似解决方案