System.Data.SQLite 数据库介绍
2010-07-15 00:00:00 来源:WEB开发网System.Data.SQLite数据库通用类的用法
下面演示一下刚刚编写的数据库通用类的用法,代码如下:
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.Common;
using System.Data.SQLite;
using SQLiteQueryBrowser;
namespace SQLiteDemo
{
class Program
{
static void Main(string[] args)
{
//CreateTable();
//InsertData();
ShowData();
Console.ReadLine();
}
public static void CreateTable()
{
string dbPath = "D:\\Demo.db3";
//如果不存在改数据库文件,则创建该数据库文件
if (!System.IO.File.Exists(dbPath))
{
SQLiteDBHelper.CreateDB("D:\\Demo.db3");
}
SQLiteDBHelper db = new SQLiteDBHelper("D:\\Demo.db3");
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 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);
}
}
}
public static void ShowData()
{
//查询从50条起的20条记录
string sql = "select * from test3 order by id desc limit 50 offset 20";
SQLiteDBHelper db = new SQLiteDBHelper("D:\\Demo.db3");
using (SQLiteDataReader reader = db.ExecuteReader(sql, null))
{
while (reader.Read())
{
Console.WriteLine("ID:{0},TypeName{1}", reader.GetInt64(0), reader.GetString(1));
}
}
}
}
}
- ››DataGrid中CheckBox绑定bool属性来进行选中判断
- ››Sqlite数据库插入和读取图片数据
- ››SYSTEM用户删除后怎么重新创建和原来SYSTEM默认一...
- ››SQLite 3.7.13的加密解密详解
- ››data/data/目录下的私有数据
- ››System Center 2012 - Unified Installer的系统要...
- ››System.Data.OleDb.OleDbException: Unspecified...
- ››SQLite加密库 SQLCipher 1.1.8 发布
- ››System.Data.SQLite 数据库介绍
- ››SQLite在ANDROID中的应用
- ››SystemServer中启动的android服务
- ››Data Web Services:访问IBM数据库服务器的新方式...
更多精彩
赞助商链接