当前位置:首页 > C# > 正文内容

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

canca15年前 (2011-05-23)C#638
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/>");
        }
   }
}


扫描二维码推送至手机访问。

版权声明:本文由Ant.Master's Blog发布,如需转载请注明出处。

本文链接:https://iant.work/post/251.html

标签: C#
分享给朋友:

“C#引用System.Data.SQLite操作SQLite数据库一例” 的相关文章

C#开发p2p

尽管有许多P2P网络不需要索引服务器或中央服务器,各客户机之间可以互相直接通讯,但下面的图1还是显示了P2P网络的基本工作原理,一般来说,P2P概念中包含一台中央索引服务器,这台服务器并不存储有任何文件,它只存储有登录到该网络上的所有用户的信息、客户端的IP地址以及用户提供的供共享的文件,客户机和服...

MD5加密C#实现

//此版本支持16位与32位的程序...//CopyRight(C) CAnca Software Office.//Created by CAnca.using System;using System.IO;using ...

C#字符输出格式控制

  C#的String.Format举例stringstr1 =string.Format("{0:N1}",56789);             &nbs...

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。