C#引用System.Data.SQLite操作SQLite数据库一例

SQLite数据库结构如下:

引用内容 引用内容
Create TABLE admin(username text,age integer);

下边用C#演示下如何对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; //引用System.Data.SQLite

public partial class Sqlite : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string _connectionString = @"Data Source=F:\mzwucom\bbs\db1.db";
        string _sql;

        SQLiteConnection conn = new SQLiteConnection();
        SQLiteCommand cmd;
        SQLiteDataReader dr;
        conn.ConnectionString = _connectionString;
        conn.Open();
        _sql = "insert into admin(username,age) values('user" + (new Random()).Next(1,100) + "',22)";
        cmd = new SQLiteCommand(_sql, conn);
        cmd.ExecuteNonQuery();
        _sql = "select * from admin";
        cmd = new SQLiteCommand(_sql, conn);
        dr = cmd.ExecuteReader();
        while (dr.Read())
        {
            Response.Write(dr["username"].ToString() + "," + dr["age"].ToString() + "<br/>");
        }
   }
}


上一篇: SQLite ADO.NET 2.0 驱动程序
下一篇: ASP操作SQLite数据库一例
文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags:
最新日志:
评论: 0 | 引用: 0 | 查看次数: 14670
发表评论
登录后再发表评论!