public static void CreateTable() { //如果不存在改数据库文件,则创建该数据库文件 if (!System.IO.File.Exists(dbPath)) { SQLiteDBHelper.CreateDB(dbPath); } SQLiteDBHelper db = new SQLiteDBHelper(dbPath); string sql = "CREATE TABLE Test3(id integer NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE," + "Name char(3),TypeName varchar(50),AddDate datetime,UpdateTime Date,Time time,Comments blob)"; db.ExecuteNonQuery(sql, null); }
public static void ShowData() { //查询从50条起的20条记录 string sql = "select * from test3 order by id desc limit 50 offset 20"; SQLiteDBHelper db = new SQLiteDBHelper(dbPath); using (SQLiteDataReader reader = db.ExecuteReader(sql, null)) { while (reader.Read()) { Console.WriteLine("ID:{0},TypeName{1}", reader.GetInt64(0), reader.GetString(1)); } } }
public static void InsertData() { string sql = "INSERT INTO Test3(Name,TypeName,AddDate,UpdateTime,Time,Comments)" + "values(@Name,@TypeName,@AddDate,@UpdateTime,@Time,@Comments)"; SQLiteDBHelper db = new SQLiteDBHelper("D:\\Demo.db3"); for (char c = 'A'; c <= 'Z'; c++) { for (int i = 0; i < 100; i++) { SQLiteParameter[] parameters = new SQLiteParameter[] { new SQLiteParameter("@Name", c + i.ToString()), new SQLiteParameter("@TypeName", c.ToString()), new SQLiteParameter("@AddDate", DateTime.Now), new SQLiteParameter("@UpdateTime", DateTime.Now.Date), new SQLiteParameter("@Time", DateTime.Now.ToShortTimeString()), new SQLiteParameter("@Comments", "Just a Test" + i) }; db.ExecuteNonQuery(sql, parameters); } } }