How to use C # To operate SQLite Databases

Source: Internet
Author: User

The previous article has introduced the SQLite database and ADO. NET Provider for SQLite. Now we will introduce how to use c # To operate the SQLite database.

1. Download ADO. NET provider for the SQLite database engine from the http://sourceforge.net/projects/sqlite-dotnet2/files/. then install.

2. Create a console program in VS 2005 and add reference System. Data. SQLite. dll. the file is in the bin directory of the ADO. NET provider for the SQLite installation directory.

3. The using namespace can be used like other ADO. NET providers.

 

The Code is as follows:

 

Code
Static void Main (string [] args)
{
String datasource = "c:/test. db ";

If (! System. IO. File. Exists (datasource ))
SQLiteConnection. CreateFile (datasource );

SQLiteConnection conn = new SQLiteConnection ();
SQLiteConnectionStringBuilder conStr = new SQLiteConnectionStringBuilder ();

ConStr. DataSource = datasource;

Conn. ConnectionString = conStr. ToString ();

// Open connetcion
Conn. Open ();

SQLiteCommand cmd = new SQLiteCommand ();
String SQL = string. Empty;
Cmd. Connection = conn;
/*
// Create a table
String SQL = "CREATE TABLE test (username varchar (20), password varchar (20 ));";
Cmd. CommandText = SQL;
Cmd. Connection = conn;
Cmd. ExecuteNonQuery ();
*/
// Insert data

For (int I = 0; I <= 10; I ++)
{
SQL = "INSERT INTO test VALUES (cola, mypassword )";
Cmd. CommandText = SQL;
& Nbs

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.