C # getting started with Sqlite and collecting related tools

Source: Internet
Author: User
Sqlite can be used without installation.
Is Sqlite the database engine temporarily created by System. Data. SQLite. DLL?

1. Create a WinForm project and reference System. Data. SQLite. DLL. The interface is as follows:

1.1 SQLiteConnection. CreateFile ("D:/Data. db3 ");
In this way, you can create a database file with a random name.
Encapsulated into a function

// Create a database file and save it to the HyData folder in the current directory.
// CreateDB ("HyData. db3 ");
Private void CreateDB (string dbName)
{
String databaseFileName = System. Environment. CurrentDirectory + @ "/HyData/" + dbName;

SQLiteConnection. CreateFile (databaseFileName );
}

 

1.2 database connection string

String connStr = @ "Data Source =" + System. environment. currentDirectory + @ "\ HyData. db3; Initial Catalog = sqlite; Integrated Security = True; Max Pool Size = 10 ";

A HyData directory is created to store databases.

1.3 Execute SQL statements

// Execute the SQL statement
// Create a table: ExecuteSql ("create table HyTest (TestID TEXT )");
// Insert some data: ExecuteSql ("insert into HyTest (TestID) values ('20140901 ')");
Private void ExecuteSql (string sqlStr)
{
Using (DbConnection conn = new SQLiteConnection (connStr ))
{
Conn. Open ();
DbCommand comm = conn. CreateCommand ();
Comm. CommandText = sqlStr;
Comm. CommandType = CommandType. Text;
Comm. ExecuteNonQuery ();
}
}

Execute the query statement

// Execute the query
// ExecQuery ("select * from HyTest ");
Private void ExecQuery (string sqlStr)
{
Using (DbConnection conn = new SQLiteConnection (connStr ))
{
Conn. Open ();
DbCommand comm = conn. CreateCommand ();
Comm. CommandText = sqlStr;
Comm. CommandType = CommandType. Text;

Using (IDataReader reader = comm. ExecuteReader ())
{
While (reader. Read ())
{
MessageBox. Show (reader [0]. ToString ());
}
}
}
}

// Execute the query and return the DataSet
Private DataSet ExecDataSet (string sqlStr)
{
Using (SQLiteConnection conn = new SQLiteConnection (connStr ))
{
Conn. Open ();
SQLiteCommand cmd = conn. CreateCommand ();
Cmd. CommandText = sqlStr;
Cmd. CommandType = CommandType. Text;

SQLiteDataAdapter da = new SQLiteDataAdapter (cmd );
DataSet ds = new DataSet ();
Da. Fill (ds );

Return ds;
}
}

Sample project source code: HySqlite.rar http://revit.5d6d.net/thread-799-1-1.html

2. Sqlite related tools

2.1 Sqlite databases can be downloaded at www.sqlite.org, which is very small.
Or sqlite-shell-win32-x86-3070600.zip
Http://revit.5d6d.net/thread-800-1-1.html

2.2 C # The official sample code for operating Sqlite. I forgot the url.
Or http://revit.5d6d.net/thread-801-1.htmlinclude
SQLite-1.0.66.0-source.zip
SQLite-1.0.66.0-binaries.zip
Debug.rar

2.3 Sqlite interface tools

SQLiteExpertSetup.exe
Http://revit.5d6d.net/thread-802-1-1.htmlthis is a good comparison.
SQLite Database Browser.exe
Http://revit.5d6d.net/thread-803-1-1.htmlthis argument is used on a hand machine.

2.4 small interface tool SqliteSpy (thanks to http://www.cnblogs.com/qq419524837/)

Download: SQLiteSpy or http://revit.5d6d.net/thread-808-1-1.html

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.