First download ADO.NET2.0 Provider for SQLite. Download binaries zip version of it. Once downloaded decompress, you can be found in the bin directory System.Data.SQLite.DLL. In vs2008 using the Add Reference feature System.Data.SQLite.DLL added to the project in on it. Try by running the following:
String DataSource = "E: /tmp/test.db";
System.Data.SQLite.SQLiteConnection.CreateFile (DataSource);
// connect to the database
System.Data.SQLite.SQLiteConnection conn = new System.Data .SQLite.SQLiteConnection ();
System.Data.SQLite.SQLiteConnectionStringBuilder connstr new new System.Data.SQLite.SQLiteConnectionStringBuilder = ();
connstr.DataSource = DataSource;
connstr.Password = "ADMIN"; // set a password, SQLite ADO.NET to achieve a password-protected database
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(20),password varchar(20))";
cmd.CommandText = sql;
cmd.Connection = conn;
cmd.ExecuteNonQuery();
//插入数据
sql = "INSERT INTO test VALUES('a','b')";
cmd.CommandText = sql;
cmd.ExecuteNonQuery();
//取出数据
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());
C # .NET, program implementation and how the database connection SQLITE? And CRUD functionality?
Guess you like
Origin blog.csdn.net/fangyuan621/article/details/90543277
Recommended
Ranking