Chinaunix首页 | 论坛 | 博客
  • 博客访问: 165873
  • 博文数量: 36
  • 博客积分: 2160
  • 博客等级: 大尉
  • 技术积分: 382
  • 用 户 组: 普通用户
  • 注册时间: 2007-03-27 01:48
个人简介

喝喝咖啡,做做开发

文章分类
文章存档

2014年(4)

2013年(1)

2012年(4)

2011年(2)

2010年(3)

2009年(9)

2008年(3)

2007年(10)

我的朋友

分类: C#/.net

2013-11-10 04:17:34

看代码更简单明了,在项目中引用System.Data.SQLite.dll时,看情况使用何种版本,下面代码测试时使用.netFx40 binary bundle win32版

点击(此处)折叠或打开

  1.             string cnstr = "Data Source=:memory:";
  2.             SQLiteConnection cn = new SQLiteConnection(cnstr);
  3.             cn.Open();

  4.             string crtSql = "create table test (val int, str varchar(10))";
  5.             SQLiteCommand cm = new SQLiteCommand(crtSql, cn);
  6.             cm.ExecuteNonQuery();

  7.             string insSql = "insert into test values (100, 'hello')";
  8.             cm = new SQLiteCommand(insSql, cn);
  9.             cm.ExecuteNonQuery();

  10.             string cntSql = "select count(*) from test";
  11.             cm = new SQLiteCommand(cntSql, cn);
  12.             int count = Convert.ToInt32(cm.ExecuteScalar());
  13.             Console.WriteLine(string.Format("count={0}", count));

  14.             string sltSql = "select * from test";
  15.             cm = new SQLiteCommand(sltSql, cn);
  16.             SQLiteDataReader sdr = cm.ExecuteReader();
  17.             while (sdr.Read())
  18.             {
  19.                 Console.WriteLine(sdr.GetInt32(0).ToString());
  20.                 Console.WriteLine(sdr.GetString(1));
  21.             }

  22.             SQLiteConnection destcn = new SQLiteConnection(@"Data Source=G:\ProgramTest\test.db3");
  23.             destcn.Open();
  24.             cn.BackupDatabase(destcn, "main", "main", -1, null, 0);
  25.             destcn.Close();

  26.             cn.Close();

阅读(850) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~