1. Refer to SQLite ADO by add references. NET installation directory in the bin directory of the System.Data.SQLite.DLL.
2, create the database file: Because it is always a 0-byte file, you should use IO can also (?!). )。
System.Data.SQLite.SQLiteConnection.CreateFile (DataSource);
3. Connect to the database
System.Data.SQLite.SQLiteConnection conn = new System.Data.SQLite.SQLiteConnection (connectionString);
ConnectionString contains some configuration information of the database, such as database file, database open password, etc. You can use System.Data.SQLite.SQLiteConnectionStringBuilder to assist in creating connectionstring
4, creating tables, reading data, and so on and access or MS SQL is not much different.
Create a database file
String datasource= "H:/test.db";
System.Data.SQLite.SQLiteConnection.CreateFile (DataSource);
Connecting to a database
System.Data.SQLite.SQLiteConnection conn = new System.Data.SQLite.SQLiteConnection ();
System.Data.SQLite.SQLiteConnectionStringBuilder connstr = new System.Data.SQLite.SQLiteConnectionStringBuilder ();
ConnStr. DataSource = DataSource;
ConnStr. Password = "admin";//Set password, SQLite ADO. NET implements the database password protection
Conn. ConnectionString = ConnStr. ToString ();
Conn. Open ();
Create a table
System.Data.SQLite.SQLiteCommand cmd = new System.Data.SQLite.SQLiteCommand ();
String sql = "CREATE TABLE Test (username varchar (), password varchar (20))";
Cmd.commandtext=sql;
Cmd. Connection=conn;
Cmd. ExecuteNonQuery ();
Inserting data
sql = "INSERT into Test VALUES (' Dotnetthink ', ' mypassword ')";
Cmd.commandtext = SQL;
Cmd. ExecuteNonQuery ();
Remove data
sql = "SELECT * from Test";
Cmd.commandtext = SQL;
System.Data.SQLite.SQLiteDataReader reader = cmd. ExecuteReader ();
StringBuilder sb = new StringBuilder ();
while (reader. Read ())
{
Sb. Append ("Username:"). Append (reader. GetString (0)). Append ("\ n")
. Append ("Password:"). Append (reader. GetString (1));
}
MessageBox.Show (sb.) ToString ());