Raspberry Pi、C#、Monodevelop、Sqlite - 没有这样的 table,文件名未知
Raspberry Pi, C#, Monodevelop,Sqlite - no such table, filename unknown
我的 Raspberry Pi2 上有小型测试 Sqlite 数据库。
连接字符串是:
con = new SqliteConnection("Data Source=test.db,version3");
如果我想获取数据,我使用:
cmd = new SqliteCommand("SELECT * FROM users",con);
reader = cmd.ExecuteReader();
while(reader.Read()){
....
}
我得到这个异常:
Mono.Data.Sqlite.SqliteException: SQLite error
no such table: users
at Mono.Data.Sqlite.SQLite3.Prepare (Mono.Data.Sqlite.SqliteConnection cnn,
System.String strSql, Mono.Data.Sqlite.SqliteStatement previous,
UInt32 timeoutMS, System.String& strRemain) [0x00000] in <filename unknown>:0
at Mono.Data.Sqlite.SqliteCommand.BuildNextCommand () [0x00000] in <filename unknown>:0
如有任何建议,我将不胜感激。
问题出在你的连接字符串上,应该是这样的:"Data Source={path-to-your-database-file}test.db;Version=3;"
名称为 test.db,version3
的数据库文件尚不存在,因此创建它。
连接字符串参数始终必须使用等号:Version=3
。
我的 Raspberry Pi2 上有小型测试 Sqlite 数据库。
连接字符串是:
con = new SqliteConnection("Data Source=test.db,version3");
如果我想获取数据,我使用:
cmd = new SqliteCommand("SELECT * FROM users",con);
reader = cmd.ExecuteReader();
while(reader.Read()){
....
}
我得到这个异常:
Mono.Data.Sqlite.SqliteException: SQLite error
no such table: users
at Mono.Data.Sqlite.SQLite3.Prepare (Mono.Data.Sqlite.SqliteConnection cnn,
System.String strSql, Mono.Data.Sqlite.SqliteStatement previous,
UInt32 timeoutMS, System.String& strRemain) [0x00000] in <filename unknown>:0
at Mono.Data.Sqlite.SqliteCommand.BuildNextCommand () [0x00000] in <filename unknown>:0
如有任何建议,我将不胜感激。
问题出在你的连接字符串上,应该是这样的:"Data Source={path-to-your-database-file}test.db;Version=3;"
名称为 test.db,version3
的数据库文件尚不存在,因此创建它。
连接字符串参数始终必须使用等号:Version=3
。