1. Introduction to the Encyclopedia
SQLite is a lightweight database that adheres to the acid-based relational database management system, which is contained in a relatively small C library. It is the public domain project established by D.richardhipp. It is designed to be embedded, and has been used in many embedded products, it occupies a very low resource, in the embedded device, may only need hundreds of K of memory is enough. It can support Windows/linux/unix and so on mainstream operating system, and can be combined with many programming languages, such as TCL, C #, PHP, Java, and ODBC interface, also compared to MySQL, PostgreSQL, the two open source world-renowned database management system, is processing faster than they do. The first alpha version of SQLite was born in May 2000. So far there have been 14 years, SQLite also ushered in a version of SQLite 3 has been released.
2. Download and install
- Http://www.sqlite.org/download.html in precompiled Binaries for Windows to download a shell version, you can unzip, and add the extracted directory to the system's PATH variable, This can be used directly in the CMD, of course, not much can be used every time CD to directory execution
2.http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki Selected downloads by net version
If it is vs2010 please download Http://system.data.sqlite.org/downloads/1.0.94.0/sqlite-netFx40-setup-bundle-x86-2010-1.0.94.0.exe
3. Basic SQL statements
1. Build Library Sqlite3 Test.db
(Problem: The general will appear near "sqlite3": syntax error, but the search can not find, have to know how the matter, please tell me; Workaround:
Sqlite3 d:/test.db;)
2. Build tables CREATE table testtable (ID integer primary key, testname varchar (100));
3. Inserting data
4. Query data
5. Quit quit, other commands please. Help view
4. Start C # operation SQLite
1, first go to download system.data.sqlite, install, set up a console program to copy System.Data.SQLite.dll and System.Data.SQLite.Linq.dll reference
2. Create the library and connect the database in the first step
1 stringFilePath =@"D:\test.db";2 if(!file.exists (FilePath))3 {4 System.Data.SQLite.SQLiteConnection.CreateFile (FilePath);5 }6Sqliteconnection Conn =Newsqliteconnection ();7Sqliteconnectionstringbuilder connstr =NewSqliteconnectionstringbuilder ();8Connstr.datasource =FilePath;9Connstr.password ="Pguser";TenConnstr.pooling =true; OneConn.connectionstring =connstr.tostring (); AConn.Open ();
3. Create a table
CREATE TABLE Sqlitecommand cmd = new Sqlitecommand (); String sql = "CREATE TABLE Xlog (logtype varchar (), content varchar ())"; Cmd.commandtext = SQL; Cmd. Connection = Conn; Cmd. ExecuteNonQuery (); Conn.dispose ();
4. Inserting data
string sql1 = "INSERT into Xlog (logtype,content) VALUES (' test1 ', ' test2 ')"; Sqlitecommand cmd1 = new Sqlitecommand (); Cmd1.commandtext = SQL1; Cmd1. Connection = Conn; Cmd1. ExecuteNonQuery (); Conn.dispose ();
5. Enquiry
String sql3 = "SELECT * from Xlog"; Sqlitecommand cmd2 = new Sqlitecommand (); Cmd2. Connection = Conn; Cmd2.commandtext = Sql3; Sqlitedatareader Reader =CMD2. ExecuteReader (); StringBuilder sb = new StringBuilder (); while (reader. Read ()) {sb. Append ("LogType:" +reader. GetString (0)); } //conn.dispose (); Conn.close (); Console.WriteLine (sb.) ToString ()); Console.read ();
Basic operation has been completed, other extensions will require everyone to own Baidu and read http://www.sqlite.org/docs.html
VS2010 net4.0 C # operation SQLite