±¾ÎĽéÉÜÁËÈçºÎÔÚasp.net web ³ÌÐòÖÐʹÓÃSqliteǶÈëʽÊý¾Ý¿â£¬sqliteÊý¾Ý¿â¿ÉÒÔ×÷ΪÎļþ·ÅÔÚÕ¾µãµÄAPP_DATAĿ¼Ï£¬ÊʺÏСÍøվʹÓã¬Ê¹ÓÃËü²»ÐèÒªÂòsql server¿Õ¼ä£¬¶øÇÒ¾Ý˵ËüµÄÐÔÄܺܲ»´í¡£
SqliteÊÇǶÈëÊý¾Ý¿â£¬ÀàËÆÓëMS Sql Server Compact£¬Ö®ËùÒÔ²»ÓÃSql server compactÊÇÒòΪËü¼È²»Ö§³ÖSELECT TOPÒ²²»Ö§³ÖROW_NUMBER()»¹²»Ö§³ÖLIMIT£¬Ò²¾ÍÊÇÎÒûÓа취ÓÃËü·ÖÒ³ÁË£¬È¡Êý¾ÝµÄʱºò±ØÐë¸ù¾ÝÌõ¼þÈ¡£¬²»ÄÜÔÚ¸ø¶¨Ìõ¼þÏÂÈ¡nÌõ¡£
1. °²×°SqliteÊý¾Ý¿â£¬sqliteÊý¾Ý¿â·Ç³£·½±ã£¬ËûµÄ°²×°Ö»ÓÐÒ»¸öexeÎļþ£¬¿ÉÒÔÏÂÔØ¡£
ÏÂÔØ¿ÉÖ´ÐÐÎļþÖ®ºóʹÓÃÃüÁî¡°sqlite3 dbname¡±Ö´ÐоͿÉÒÔ´´½¨Êý¾Ý¿â¡£
»òÕßΪÁË¿ª·¢·½±ãÏÂÔØSqlite DeveloperÈí¼þ£¬Ê¹ÓÃÈí¼þ´´½¨Ò²Óз½±ã¡£ÏÂÔØÁ´½Ó
2. °²×°dot netϵÄSqliteÊý¾Ý¿âÇý¶¯£¬Æäʵ¾ÍÊÇÒ»¸ödll£¬System.Data.SQLite,ËûÊÇÒ»¸ö¿ªÔ´ÏîÄ¿£¬¿ÉÒÔµ½SourceForgeÉÏÏÂÔØ
3. ÔÚVSÖн¨Á¢Ò»¸öWeb Application£¬²¢ÒýÓÃ2ÖеÄdll
4. ÔÚdefault.aspxµÄcsÎļþÖÐʵÏÖ·ÃÎÊSqliteµÄ´úÂ룬´úÂëºÍ×¢ÊÍÈçÏ£º
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SQLite;
namespace SqliteWebApp
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//Õâ¸öÎļþÊÇÔ¤ÏÈÉú³ÉµÄÊý¾Ý¿âÎļþ
string sqliteFilePath = Server.MapPath("~/App_Data/firstsqlite.db");
DataSet ds = new DataSet();
//ÉùÃ÷Ò»¸öSqliteÊý¾Ý¿âµÄÁ´½Ó
using (SQLiteConnection conn = new SQLiteConnection("Data Source=" + sqliteFilePath))
{
//´´½¨sqliteÃüÁî
using (SQLiteCommand comm = conn.CreateCommand())
{
//´ò¿ªÊý¾Ý¿âÁ´½Ó
conn.Open();
//²åÈëÊý¾Ý
comm.CommandText = "INSERT INTO [t] VALUES(10,'Hello 9')";
comm.ExecuteNonQuery();
//¸üÐÂÊý¾Ý
comm.CommandText = "UPDATE [t] SET name = 'Hello 10' WHERE id = 10";
comm.ExecuteNonQuery();
//ʹÓòÎÊý²åÈëÊý¾Ý
comm.CommandText = "INSERT INTO [t] VALUES(@id,@name)";
comm.Parameters.AddRange(
new SQLiteParameter[]{
CreateSqliteParameter("@id",DbType.Int32,4,11),
CreateSqliteParameter("@name",DbType.String,10,"Hello 11")
});
comm.ExecuteNonQuery();
comm.Parameters.Clear();
//selectÊý¾Ý·ÖÒ³ÓÃlimit¾ÍÐУ¬ºÜ·½±ã
comm.CommandText = "Select * From MAIN.[t]";
using (SQLiteDataAdapter adapter = new SQLiteDataAdapter(comm))
{
adapter.Fill(ds);
}
}
}
gv1.DataSource = ds;
gv1.DataBind();
}
/**//// <summary>
/// ·Å»ØÒ»¸öSQLiteParameter
/// </summary>
/// <param name="name">²ÎÊýÃû×Ö</param>
/// <param name="type">²ÎÊýÀàÐÍ</param>
/// <param name="size">²ÎÊý´óС</param>
/// <param name="value">²ÎÊýÖµ</param>
/// <returns>SQLiteParameterµÄÖµ</returns>
static private SQLiteParameter CreateSqliteParameter(string name,DbType type,int size,object value)
{
SQLiteParameter parm = new SQLiteParameter(name,type, size);
parm.Value = value;
return parm;
}
}
}
×îºóÏ£ÍûµÄMS Sql Server Compact¿ÉÒÔ×öһЩ¸Ä½ø£¬ÈÃÎÒÃÇ¿ÉÒÔÊæ·þµÄʹÓá£