aspx页面仅包含一按钮btnTest,在页面aspx.cs页面中,引入命名空间,贴入以下类似代码即可.    

     图片 1

复制代码 代码如下:

     然后,在项目中添加上图所选项即可.

要想在ASP.NET项目中使用SQLite数据库,先需下载一个ADO.NET 2.0 SQLite Data
Provider,下载地址为:,下载后安装完毕后,该安装程序自动在在系统注册(即可在”添加引用”中看到所安装的Provider).    

using System;
using System.Data;
using System.Web.UI.WebControls;
using System.Data.SQLite;

cmd.CommandText = “select * from Users “;
cmd.Connection = conn;
SQLiteDataReader sdrInfo = cmd.ExecuteReader();
if (sdrInfo!= null)
{
int userID = 0;
string userName = string.Empty;
string userPassword = string.Empty;
while(sdrInfo.Read())
{
userID = Convert.ToInt32(sdrInfo[“UserID”]);
userName = sdrInfo[“UserName”].ToString();
userPassword = sdrInfo[“UserPassword”].ToString();
Response.Write(“UserID:”+userID+”<br />”);
Response.Write(“UserName:” + userName+ “<br />”);
Response.Write(“UserPassword:” + userPassword + “<br />”);
Response.Write(“<br />”);
}
sdrInfo.Close();
sdrInfo.Dispose();
}
cmd.CommandText = “update Users set UserPassword=’linxiang'”;
cmd.Connection = conn;
cmd.ExecuteNonQuery();
Response.Write(“更新数据库中的数据成功.”);
Response.Write(“以下结果为查询从数据库中经过编辑过后的数据项<br
/><br />”);
cmd.CommandText = “select * from Users “;
cmd.Connection = conn;
sdrInfo = cmd.ExecuteReader();
if (sdrInfo 在项目中添加上图所选项即可.。!= null)
{
int userID = 0;
string userName = string.Empty;
string userPassword = string.Empty;
while (sdrInfo.Read())
{
userID = Convert.ToInt32(sdrInfo[“UserID”]);
userName = sdrInfo[“UserName”].ToString();
userPassword = sdrInfo[“UserPassword”].ToString();
Response.Write(“UserID:” + userID + “<br />”);
Response.Write(“UserName:” + userName + “<br />”);
Response.Write(“UserPassword:” + userPassword + “<br />”);
Response.Write(“<br />”);
}
在项目中添加上图所选项即可.。sdrInfo.Close();
sdrInfo.Dispose();
}
conn.Clone();
conn.Dispose();
}
}

在项目中添加上图所选项即可.。public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnTest_Click(object sender, EventArgs e)
{
SQLiteConnection.ClearAllPools();
SQLiteConnection.CreateFile(Server.MapPath(“~”) + “/UserData.dbx”);
SQLiteConnection conn = new SQLiteConnection(“Data Source=” +
Server.MapPath(“~” + “/UserData.dbx”));
conn.Open();
Response.Write(“打开数据库成功<br />”);
SQLiteCommand cmd = new SQLiteCommand();
cmd.CommandText = “create table Users (UserID int primary key,UserName
varchar(100) not null,UserPassword varchar(100) not null)”;
cmd.Connection = conn;
cmd.ExecuteNonQuery();
for (int i = 0; i < 100;i++ )
{
cmd.CommandText = “insert into Users (UserID,UserName,UserPassword)
values (” + i + “,’TestUser_” + i + “‘,'” +
DateTime.Now.ToString().Replace(” “, “-“).Replace(“:”, “-“) + “‘)”;
cmd.ExecuteNonQuery();
}
Response.Write(“插入成功
<br />”);
cmd.CommandText = “select Username from Users where UserID=1”;
cmd.Connection = conn;
string tempUserName = cmd.ExecuteScalar().ToString();
Response.Write(“单个值查询结果为:” + tempUserName + “<br /><br
/>”);

您可能感兴趣的文章:

  • C#操作SQLite方法实例详解
  • C#中使用SQLite数据库的方法介绍
  • C#操作SQLite数据库方法小结(创建,连接,插入,查询,删除等)
  • C#中实现在32位、64位系统下自动切换不同的SQLite
    dll文件
  • C#实现Excel导入sqlite的方法
  • C#基于SQLiteHelper类似SqlHelper类实现存取Sqlite数据库的方法
  • C#简单访问SQLite数据库的方法(安装,连接,查询等)
  • c#几种数据库的大数据批量插入(SqlServer、Oracle、SQLite和MySql)
  • C#解决SQlite并发异常问题的方法(使用读写锁)
  • C#
    SQLite执行效率的优化教程

相关文章