SoFunction
Updated on 2025-03-07

(C#) Operating SQLite database instance


using System;
using ;
using ;
using ;

public partial class _Default :
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnTest_Click(object sender, EventArgs e)
{
();
(("~") + "/");
SQLiteConnection conn = new SQLiteConnection("Data Source=" + ("~" + "/"));
();
("The database was opened successfully~~<br />");
SQLiteCommand cmd = new SQLiteCommand();
= "create table Users (UserID int primary key,UserName varchar(100) not null,UserPassword varchar(100) not null)";
= conn;
();
for (int i = 0; i < 100;i++ )
{
= "insert into Users (UserID,UserName,UserPassword) values (" + i + ",'TestUser_" + i + "','" + ().Replace(" ", "-").Replace(":", "-") + "')";
();
}
("Insert successfully~~<br />");
= "select Username from Users where UserID=1";
= conn;
string tempUserName = ().ToString();
("Single value query result is:" + tempUserName + "<br /><br />");

= "select * from Users ";
= conn;
SQLiteDataReader sdrInfo = ();
if (sdrInfo!= null)
{
int userID = 0;
string userName = ;
string userPassword = ;
while(())
{
userID = Convert.ToInt32(sdrInfo["UserID"]);
userName = sdrInfo["UserName"].ToString();
userPassword = sdrInfo["UserPassword"].ToString();
("UserID:"+userID+"<br />");
("UserName:" + userName+ "<br />");
("UserPassword:" + userPassword + "<br />");
("<br />");
}
();
();
}
= "update Users set UserPassword='linxiang'";
= conn;
();
("Update the data in the database successfully.");
("The following results are the edited data items from the database after querying<br /><br />");
= "select * from Users ";
= conn;
sdrInfo = ();
if (sdrInfo != null)
{
int userID = 0;
string userName = ;
string userPassword = ;
while (())
{
userID = Convert.ToInt32(sdrInfo["UserID"]);
userName = sdrInfo["UserName"].ToString();
userPassword = sdrInfo["UserPassword"].ToString();
("UserID:" + userID + "<br />");
("UserName:" + userName + "<br />");
("UserPassword:" + userPassword + "<br />");
("<br />");
}
();
();
}
();
();
}
}