我想使用此链接https://github.com/praeclarum/sqlite-net提供的 sqlite-net 。
不幸的是,入门文档还不够。它甚至没有提到如何创建数据库。我尝试查看示例,不幸的是,示例已损坏(无法编译、运行时错误等)。
我可以在网上找到的最实用的教程是http://blog.tigrangasparian.com/2012/02/09/getting-started-with-sqlite-in-c-part-one/
不幸的是,sqlite-net 不完全支持 sqlite.org sqlite 实现,因此使教程对 praeclarum sqlite-net 毫无用处。
从教程中但在 praeclarum sqlite-net 中做同样事情的等效方法是什么?
从教程
创建数据库(这是我卡住的地方)
SQLiteConnection.CreateFile("MyDatabase.sqlite");
连接到数据库
SQLiteConnection m_dbConnection;
m_dbConnection = new SQLiteConnection("Data Source=MyDatabase.sqlite;Version=3;");
m_dbConnection.Open();
创建表
string sql = "create table highscores (name varchar(20), score int)";
SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection);
command.ExecuteNonQuery();
填表
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"]);