2024年4月28日发(作者:)

入手。。。

首先import/using:

代码

using ;

Connection和Command:

代码

private SQLiteConnection conn;

private SQLiteCommand cmd;

连接db:

代码

conn = new SQLiteConnection("Data Source=c:");

();

INSERT/UPDATE:

代码

cmd = Command();

dText = "INSERT INTO user(email,name) VALUES ('email','name')";

eNonQuery();

dText = "UPDATE userSET name = 'Codelicious' WHERE ID = 1";

eNonQuery();

SELECT:

代码

dText = "SELECT ID, name FROM user";

SQLiteDataReader reader = eReader();

if (s)

{

while (())

{

ine("ID: " + 16(0));

ine("name: " + ing(1));

}

}

模板程序:

using System;

using ;

using ;

using ;

namespace SQLiteQueryBrowser

{

///

/// 说明:这是一个针对的数据库常规操作封装的通用类。

/// 作者:zhoufoxcn(周公)

/// 日期:2010-04-01

/// Blog: or /zhoufoxcn

/// Version:0.1

///

public class SQLiteDBHelper

{

private string connectionString = ;

///

/// 构造函数

///

/// SQLite数据库文件路径

public SQLiteDBHelper(string dbPath)

{

tionString = "Data Source=" + dbPath;

}

///

/// 创建SQLite数据库文件

///

/// 要创建的SQLite数据库文件路径

public static void CreateDB(string dbPath)

{

using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + dbPath))

{

();

using (SQLiteCommand command = new SQLiteCommand(connection))

{

dText = "CREATE TABLE Demo(id integer NOT NULL PRIMARY KEY AUTOINCREMENT

UNIQUE)";

eNonQuery();

dText = "DROP TABLE Demo";

eNonQuery();

}

}