C # An example of operating the SQLite database by referencing System. Data. SQLite

Source: Internet
Author: User
The SQLite database structure is as follows: Create TABLE admin (username text, age integer );

The following uses C # to demonstrate how to add, query, modify, and delete records in the SQLite database:

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; // reference 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/> ");
}
}
}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.