用NuGet包管理器,能夠很方便安裝sqlite到項目中,而後引用python
using System.Data.SQLite;sql
第一步用SQLiteConnection創建鏈接。數據庫
第二步用SQLiteCommand操做數據庫,增刪改等。code
第三步用SQLiteDataReader,查詢數據庫。sqlite
完整代碼以下rem
using (SQLiteConnection conn = new SQLiteConnection()) { string dbPath = "Data Source=" + Environment.CurrentDirectory + @"\Actress.db"; conn.ConnectionString = dbPath; conn.Open(); using (SQLiteCommand cmd = new SQLiteCommand(conn)) { cmd.CommandText = @"create table if not exists Actress (ID integer primary key autoincrement, Name text not null, Age integer not null)"; cmd.ExecuteNonQuery(); cmd.CommandText = @"insert into Actress values (null,'王菲',47), (null,'范冰冰',37), (null,'柳巖',36)"; cmd.ExecuteNonQuery(); cmd.CommandText = @"select * from Actress"; using (SQLiteDataReader reader = cmd.ExecuteReader()) { if (reader.HasRows) { while(reader.Read()) { Console.WriteLine("ID: " + reader.GetInt64(0)); Console.WriteLine("Name " + reader.GetString(1)); Console.WriteLine("Age " + reader.GetInt32(2)); } } } } } Console.ReadKey();
操做上彷佛比pythoncmd