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)
{
Ïà¹ØÎĵµ£º
SQLiteСÇɵÄÌØµãʹÆäÔÚǶÈëʽÉÏÀûÓúܹ㷺¡£Ô½À´Ô½¶àµÄÒÆ¶¯É豸ÉϼÓÈëÁËSQLiteÄ£¿é£¬android,sysmbian, iphone,...ÏÂÃæµÄ½éÉÜÈÃÄã¿ìËÙ²½ÈëSQLiteµÄ´óÃÅ¡£
1. ÏÂÔØ
SQLiteÊÇ¿ªÔ´µÄÏîÄ¿£¬ËùÒÔÄã¿ÉÒÔÏÂÔØÍêËÙµÄÔ´´úÂë¡£¿ª·¢µÄʱºòÄã¿ÉÒÔ°ÑÔ´´úÂëǶÈëÄãµÄ¹¤³Ìµ±ÖУ¬Ò²¿ÉÒÔÓñàÒë ......
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/ ......
Ö÷Ҫͨ¹ýpragmaÖ¸ÁîÀ´ÊµÏÖ¡£
±ÈÈ磺 ¿Õ¼äÊÍ·Å¡¢´ÅÅÌͬ²½¡¢Cache´óСµÈ¡£
²»Òª´ò¿ª¡£Ç°ÎÄÌá¸ßÁË£¬VacuumµÄЧÂʷdz£µÍ£¡
PRAGMA auto_vacuum;
PRAGMA auto_vacuum = 0 | 1;
²éѯ»òÉèÖÃÊý¾Ý¿âµÄauto-vacuum±ê¼Ç¡£
Õý³£Çé¿öÏ£¬µ±Ìá½»Ò»¸ö´ÓÊý¾Ý¿âÖÐɾ³ýÊý¾ÝµÄÊÂÎñʱ£¬Êý¾Ý¿âÎļþ²»¸Ä±ä´óС¡£Î´Ê¹ÓõÄÎļþÒ³±»±ê¼Ç²¢ÔÚÒÔ ......
ÅÐ¶Ï±í´æÔڵķ½·¨ºÜ¼òµ¥,ÍøÉϺܶà:
SELECT COUNT(*) from sqlite_master where type='table' and name='%s'" % tname;
ÄÇôÅжÏ×Ö¶ÎÊÇ·ñ´æÔÚ, »òÕß˵ÈçºÎÅжϱíµÄ°æ±¾ÊÇ·ñ×îоÍÖ»ÐèÒª:
select * from sqlite_master where tbl_name='tblContactList';
sqlite_master µÄ±í½á¹¹ÈçÏÂ:
type |name  ......
ǶÈëʽÊý¾Ý¿âSQLiteÓëJava
SQLite×÷Ϊһ¸ö¿ªÔ´µÄǶÈëʽÊý¾Ý¿â²úÆ·£¬¾ßÓÐϵͳ¿ªÏúС£¬¼ìË÷ЧÂʸߵÄÌØÐÔ£¬ÊÊÓÃÓÚÊÖ»ú¡¢PDA¡¢»ú¶¥ºÐÉ豸µÈµçÆ÷£¬²¢ÇÒ×÷ΪǶÈëʽÊý¾Ý¿âÔÚ¿ÉÏÂÔØµÄÏû·ÑÀàÓ¦ÓóÌÐòÖÐÔËÐеĺܺá£ÕâÆªÎÄÕ½éÉÜǶÈëʽÊý¾Ý¿â²úÆ·SQLiteµÄ¼¼ÊõÌØµã£¬²¢×ÅÖØÌÖÂÛÑо¿ÓëJavaÓïÑÔÖ®¼äµÄ½Ó¿Ú£¬²¢ÒÔʵÀý˵Ã÷ÈçºÎʹÓÃJAVA¿ª· ......