看代码更简单明了,在项目中引用System.Data.SQLite.dll时,看情况使用何种版本,下面代码测试时使用.netFx40 binary bundle win32版
-
string cnstr = "Data Source=:memory:";
-
SQLiteConnection cn = new SQLiteConnection(cnstr);
-
cn.Open();
-
-
string crtSql = "create table test (val int, str varchar(10))";
-
SQLiteCommand cm = new SQLiteCommand(crtSql, cn);
-
cm.ExecuteNonQuery();
-
-
string insSql = "insert into test values (100, 'hello')";
-
cm = new SQLiteCommand(insSql, cn);
-
cm.ExecuteNonQuery();
-
-
string cntSql = "select count(*) from test";
-
cm = new SQLiteCommand(cntSql, cn);
-
int count = Convert.ToInt32(cm.ExecuteScalar());
-
Console.WriteLine(string.Format("count={0}", count));
-
-
string sltSql = "select * from test";
-
cm = new SQLiteCommand(sltSql, cn);
-
SQLiteDataReader sdr = cm.ExecuteReader();
-
while (sdr.Read())
-
{
-
Console.WriteLine(sdr.GetInt32(0).ToString());
-
Console.WriteLine(sdr.GetString(1));
-
}
-
-
SQLiteConnection destcn = new SQLiteConnection(@"Data Source=G:\ProgramTest\test.db3");
-
destcn.Open();
-
cn.BackupDatabase(destcn, "main", "main", -1, null, 0);
-
destcn.Close();
-
-
cn.Close();
阅读(850) | 评论(0) | 转发(0) |