选择返回无结果

翁盖恩盖

在我的数据库中,我有一个名为 的表books,实际上只有一条记录。

ID | NAME
---------
1  | Alice in Wonderland

我想选择所有可用的记录,所以我做了:

var m_dbConnection = new SQLiteConnection("Data Source=MyDatabase.sqlite;Version=3;");
m_dbConnection.Open();

string sql = "SELECT * FROM Books";
var command = new SQLiteCommand(sql, m_dbConnection );
SQLiteDataReader reader = command .ExecuteReader();

reader返回任何结果。为什么?

奥萨夫·拉希德

您的代码不会显示您显示数据的位置或抛出异常的位置。但是,尝试SqlLiteCommand.Prepare方法:

 var command = new SQLiteCommand(sql, m_dbConnection );
 command.Prepare();

 ///and use While statement for the reader

While dr.read
{
 }

如果这不起作用Datatable,请尝试 a并查看结果是否相同(尽管它根本没有任何区别):

SqLiteDataAdapter ada = new SqliteDataAdapter(command);
DataTable dt = new DataTable;

ada.Fill(dt);
myDataGridView.Datasource=dt;

///or

string vale = dt.Rows(0)(1).ToString;

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章