C#与Sqlite数据库操作实例
这是一个有关分页的实例,仅供参考(代码来自网络)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SQLite;
using System.Threading;
using System.Collections;
using System.IO;
namespace ReadCardDemo
{
public partial class Form3 : Form
{
Form4 form4 = new Form4();
int pageSize = 12; //每页显示行数
int nMax = 0; //总记录数
int totalPage = 0; //总页数=总记录数/每页显示行数
int currentPage = 1; //当前页号
int pageCount = 0; //当前页数的记录数
int selectRow; //当前选中的行数
DataSet dataSet = new DataSet();
DataTable dataTable = new DataTable();
SQLiteDataAdapter dataAdapter;
SQLiteConnection conn = new SQLiteConnection();
SQLiteCommand cmd;
SQLiteDataReader dr;
string datasource;
string _sql;
public Form3()
{
InitializeComponent();
}
//初始化数据
public void InitializeDataSource()
{
dataTable.Clear();
dataTable.AcceptChanges();
//创建数据库
//datasource = "/Windows/ReadCardDemo/PersonId.db";
//SQLiteConnection.CreateFile(datasource);
//建立数据库连接
datasource = @"Data Source=/Windows/ReadCardDemo/PersonId.db";
conn.ConnectionString = datasource;
//获取当前数据库的记录数
_sql = "select count(*) from PersonId";
conn.Open();
cmd = new SQLiteCommand(_sql, conn);
dr = cmd.ExecuteReader();
while (dr.Read())
{
try
{
nMax = Convert.ToInt32(dr.GetValue(0));
}
catch(Exception e)
{
相关文档:
文章来源于http://blog.csdn.net/ast_224/archive/2009/01/08/3734099.aspx
......
Where is SQLite?
SQLite is available on the Android device itself. The executable is in the /system/bin directory of the device. You can see that this directory contains the shell commands like ls, ps, etc., as well as sqlite3, dalvikvm, and dexdump utilities.
Code Listing 1. Contents of system/ ......
SQLite 作为一个轻量级嵌入式数据库,还是非常好用的。雨痕极力推荐~~~~~~
今天有个朋友测试 SQLite,然后得出的结论是:SQLite 效率太低,批量插入1000条记录,居然耗时 2 分钟!
下面是他发给我的测试代码。我晕~~~~~~
using System.Data;
using System.Data.Common;
using System.Data.SQLite;
// 创 ......
SQLite和其他大部分现代SQL数据库在基本设计目标上是不同的,它的目标是简单。SQLite遵循这一目标,即使这样偶尔会导致某些特性实现的低效化。下面列举了SQLite的一些缺陷:
SQL-92特性方面
正如前面提到的,SQLite不支持SQL-92的在很多企业数据库系统中可用的一些特性。
如:
外键约束(可解析的,但非强制)
很多ALT ......