目录
1.下载sqlite
2.创建数据库及表操作
创建数据库:
打开sqlite3.exe,使用. open test.db可以进入同目录下的 test.db数据库,如果没有该数据库,会自动创建该数据库。
或者代码创建(要添加引用,之后会讲):
var fileName = AppDomain.CurrentDomain.BaseDirectory + "test.db"; ; SQLiteConnection.CreateFile(fileName);
创建表:create table t1(id int ,name varchar(50))

其实建表的语句就是sql语句。
更方便的方式是SQLite数据库查看工具,图形化操作。个人喜欢用DB Browser for SQLite,下载地址:https://sqlitebrowser.org/dl/
或者https://download.csdn.net/download/Yyuanyuxin/12326735

3.在VS上使用sqlite
this.dataGridView1.DataSource = Query("SELECT * FROM table1").Tables[0];
using System.Data.SQLite; //查询数据库,返回表 public static DataSet Query(string SQLString) {
string path = AppDomain.CurrentDomain.BaseDirectory + "test.db"; //数据库连接字符串 string connectionString = "Data Source=" + path; using (SQLiteConnection connection = new SQLiteConnection(connectionString)) {
DataSet ds = new DataSet(); try {
connection.Open(); SQLiteDataAdapter command = new SQLiteDataAdapter(SQLString, connection); command.Fill(ds, "ds"); } catch (System.Data.SQLite.SQLiteException ex) {
throw new Exception(ex.Message); } return ds; } }
关于SQLite中“其他信息: 未能加载文件或程序集“System.Data.SQLite, Version=1.0.81.0, Culture=neutral, PublicKeyToken=db“
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/223874.html原文链接:https://javaforall.net
