C Simple Access to SQLite Database of Installation Connection Query etc

  • 2021-10-24 23:28:56
  • OfStack

This article illustrates how C # can simply access an SQLite database. Share it for your reference, as follows:

Download the latest version of SQLite (http://www. sqlite. org/download. html). Other versions are OK. The version used here is sqlite-3_6_6_1

a. copy c after decompression:\ sqlite-3_6_6_1

b. Enter cmd mode, enter sqlite-3_6_6_1 directory, and execute sqlite3 mytest. db

c.


create table test (seq int,desc varchar(8));
insert into mytable1 values (1,'item');

Data establishment completed

2. Download System.Data.SQLite (http://sqlite.phxsoftware.com/) and install it. After installation, there will be detailed DEMO and documents. Please check it in detail.

3. Copy mytest. db to the Bin/Debug directory.

4. Open VS 2005 and refer to System. Data. SQLite. DLL under the System. Data. SQLite installation directory


using System.Data.SQLite;
SQLiteConnection cnn = new SQLiteConnection();
cnn.ConnectionString = @"Data Source=mytest.db;Pooling=true;FailIfMissing=false"
cnn.Open();
SQLiteCommand cmd = new SQLiteCommand();
cmd.Connection = cnn;
cmd.CommandText = "SELECT * FROM test";
SQLiteDataAdapter da = new SQLiteDataAdapter();
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds);
//  Paged query display statement 
Select * From test Limit 10 Offset 10;

The above statement means to get data from Account table, skip 10 rows and fetch 10 rows

For more readers interested in C # related content, please check the topics on this site: "Summary of thread usage skills in C # programming", "Summary of C # operating Excel skills", "Summary of XML file operation skills in C #", "C # common control usage tutorial", "WinForm control usage summary", "C # data structure and algorithm tutorial", "C # array operation skills summary" and "C # object-oriented programming introduction tutorial"

I hope this article is helpful to everyone's C # programming.


Related articles: