求助,VS2015怎么连接SQLite数据库,大神来吧
找到C#下SQLite操作驱动dll并下载:System.Data.SQLite
在项目中添加dll的引用
创建数据库(文件):
SQLiteConnection.CreateFile("MyDatabase.sqlite");
连接数据库:
SQLiteConnection m_dbConnection=new SQLiteConnection("Data 姿如Source=MyDatabase.sqlite;Version=3;");
m_dbConnection.Open();
插入数据:
String sql = "insert into highscores (name, score) values ('Me', 3000)";
SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection);
command.ExecuteNonQuery();
sql = "insert into highscores (name, score) values ('Myself', 6000)"; 和滚
command = new SQLiteCommand(sql, m_dbConnection);
command.ExecuteNonQuery(); 唤册余
sql = "insert into highscores (name, score) values ('And I', 9001)";
command = new SQLiteCommand(sql, m_dbConnection);
command.ExecuteNonQuery();
查询:
string sql = "select * from highscores order by score desc";
SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection);
SQLiteDataReader reader = command.ExecuteReader();
while (reader.Read())
Console.WriteLine("Name: " + reader["name"] + "\tScore: " + reader["score"]);
Console.ReadLine();
2024-10-28 广告