时间:2021-07-01 10:21:17 帮助过:29人阅读
可通过下面的样例程序调用,
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SQLiteDemo
{
class Program
{
static void Main(string[] args)
{
string database = "test.db";
string tablename = "TABLE1";
string[] columns = new string[] { "ID", "NAME", "SALARY"};
SQLiteType[] types = new SQLiteType[] { SQLiteType.INTEGER, SQLiteType.TEXT, SQLiteType.REAL };
string[] infos = new string[] { "PRIMARY KEY", "NOT NULL", "" };
SQLiteHelper helper = new SQLiteHelper(database);
helper.CreateTable(tablename, columns, types, infos);
Random r = new Random();
for (int i = 0; i < 5; i++)
{
string[] values = new string[] { i.ToString(), Guid.NewGuid().ToString(), (r.NextDouble() * 10000).ToString() };
helper.InsertData(tablename, types, values);
}
System.Data.DataSet ds = helper.Select(tablename, null, null);
System.Data.DataTable dt = ds.Tables[0];
for (int i = 0; i < dt.Rows.Count; i++)
{
for (int j = 0; j < dt.Columns.Count; j++)
{
Console.Write(columns[j] + " : " + dt.Rows[i][j].ToString());
if (j != dt.Columns.Count - 1)
{
Console.Write(", ");
}
else
{
Console.Write("\n");
}
}
}
Console.WriteLine();
string[] newValues = new string[] { "10", "‘James‘", "12345.67" };
string condition1 = "ID = 3";
helper.UpdateData(tablename, columns, newValues, condition1);
string condition2 = "ID = 2 OR ID = 0";
helper.DeleteData(tablename, condition2);
newValues = new string[] { "123", "Clark", "7654.32" };
string condition3 = "ID = 1";
helper.UpdateBinary(tablename, columns, newValues, types, condition3);
System.Data.SQLite.SQLiteDataReader reader = helper.Select("SELECT * FROM " + tablename);
while(reader.Read())
{
for (int i = 0; i < columns.Length; i++ )
{
Console.Write(columns[i] + " : " + reader[columns[i]]);
if (i != columns.Length-1)
{
Console.Write(", ");
}
else
{
Console.Write("\n");
}
}
}
helper.DropTable(tablename);
Console.Read();
}
}
}
运行结果如下。
整个VS工程可在下面的网址下载
https://download.csdn.net/download/u014559935/12528241
推荐:站长
C#中使用SQLite
标签:man while select 增删改查 nec down 类型 values console