登录 注册
当前位置:主页 > 资源下载 > 32 > Sqlite 操作类 C# .net下载

Sqlite 操作类 C# .net下载

  • 更新:2024-06-22 14:00:38
  • 大小:389KB
  • 推荐:★★★★★
  • 来源:网友上传分享
  • 类别:C# - 后端
  • 格式:RAR

资源介绍

Sqlite 操作类 C# .net,嵌入式SQL //创建一个数据库文件 string datasource = @"d:/ChinaPower.s3db"; // System.Data.SQLite.SQLiteConnection.CreateFile(datasource); //连接数据库 System.Data.SQLite.SQLiteConnection conn = new System.Data.SQLite.SQLiteConnection(); System.Data.SQLite.SQLiteConnectionStringBuilder connstr = new System.Data.SQLite.SQLiteConnectionStringBuilder(); connstr.DataSource = datasource; conn.ConnectionString = connstr.ToString(); conn.Open(); //创建表 System.Data.SQLite.SQLiteCommand cmd = new System.Data.SQLite.SQLiteCommand(); // string sql = "CREATE TABLE test(username varchar(20),password varchar(20))"; // cmd.CommandText = sql; cmd.Connection = conn; // cmd.ExecuteNonQuery(); //插入数据 // sql = "INSERT INTO test VALUES('ekinglong','mypassword')"; // cmd.CommandText = sql; //cmd.ExecuteNonQuery(); //取出数据 string sql = "SELECT * FROM score"; cmd.CommandText = sql; System.Data.SQLite.SQLiteDataReader reader = cmd.ExecuteReader(); StringBuilder sb = new StringBuilder(); while (reader.Read()) { sb.Append("username:").Append(reader.GetInt32(0)).Append("\n") .Append("password:").Append(reader.GetString(1)); } Console.WriteLine(sb); Console.Read();