复制代码 代码如下:
SQLiteConnection cn = new SQLiteConnection("Data Source=|DataDirectory|省市.db;Version=3");
SQLiteCommand cmd = new SQLiteCommand("select count(*) from city", cn);
cn.Open();
int recordCount = (int)(Int64)cmd.ExecuteScalar();
cn.Close();
Response.Write(recordCount);
复制代码 代码如下:
SQLiteConnection cn = new SQLiteConnection("Data Source=c://测试.db3;Version=3;password=12345");
SQLiteCommand cmd = new SQLiteCommand("select count(*) from test", cn);
cn.Open();
int recordCount = (int)(Int64)cmd.ExecuteScalar();
Response.Write("当前的总记录数:" + recordCount + "<br/>");
for (int i = 0; i < 1000; i++)
{
cmd.CommandText = "insert into test values(@id,@name,@password)";
cmd.Parameters.AddWithValue("@id", i);
cmd.Parameters.AddWithValue("@name", "姓名" + i);
cmd.Parameters.AddWithValue("@password", (i * 2).ToString());
cmd.ExecuteNonQuery();
}
cmd.CommandText = "select count(*) from test";
recordCount = (int)(Int64)cmd.ExecuteScalar();
cn.Close();
Response.Write("当前的总记录数:" + recordCount + "<br/>");
复制代码 代码如下:
SQLiteConnection cn = new SQLiteConnection("Data Source=c://测试.db3;Version=3;password=12345");
SQLiteCommand cmd = new SQLiteCommand("select count(*) from test", cn);
cn.Open();
int recordCount = (int)(Int64)cmd.ExecuteScalar();
Response.Write("当前的总记录数:" + recordCount + "<br/>");
SQLiteTransaction tran = cn.BeginTransaction();
cmd.Transaction = tran;
try
{
for (int i = 0; i < 1000; i++)
{
cmd.CommandText = "insert into test values(@id,@name,@password)";
cmd.Parameters.AddWithValue("@id", i);
cmd.Parameters.AddWithValue("@name", "姓名" + i);
cmd.Parameters.AddWithValue("@password", (i * 2).ToString());
cmd.ExecuteNonQuery();
}
tran.Commit();
}
catch
{
tran.Rollback();
Response.Write("执行出错!");
}
finally
{
cmd.CommandText = "select count(*) from test";
recordCount = (int)(Int64)cmd.ExecuteScalar();
cn.Close();
Response.Write("当前的总记录数:" + recordCount + "<br/>");
}
复制代码 代码如下:
SQLiteData md = new SQLiteData("Data Source=c://测试.db3;Version=3;password=12345");
int recordCount = (int)(Int64)md.ExecuteScalar("select count(*) from test");
Response.Write("当前的总记录数:" + recordCount + "<br/>");
md.CreateTransaction();
try
{
for (int i = 0; i < 1000; i++)
md.ExecuteNonQuery("insert into test values(@id,@name,@password)", "@id", i, "@name", "姓名" + i, "@password", (i * 2).ToString());
md.CommitTransaction();
}
catch
{
md.RollBack();
Response.Write("执行出错!");
}
finally
{
recordCount = (int)(Int64)md.ExecuteScalar("select count(*) from test");
md.Close();
Response.Write("当前的总记录数:" + recordCount + "<br/>");
}
【SQLite相关有用的链接地址】
SQLite官方网站:
SQLite内置核心函数参考文档:
SQLite日期时间函数参考文档:
SQLite数学函数参考文档:
SQLite相关SQL语法参考文档:
System.Data.SQLite.dll数据访问驱动下载地址:
新闻热点
疑难解答
图片精选