-
Sqlite 操作类 C# .net下载
资源介绍
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();
- 上一篇: C#String.Format数字格式化
- 下一篇: C#重要知识之——泛型列表List
例子