SQLiteDataAdapter 未填充指定的 DataTable
我正在尝试从 SQLite 数据库中提取一些数据,以便可以在 GUI 中填充 GridView:这是返回 DataTable 的代码:
DataTable table = new DataTable();
SQLiteDataAdapter adapter = new SQLiteDataAdapter(this.command.CommandText, this.connection);
adapter.Fill(table);
return table;
出于某种原因,在调用 adapter.Fill
后,DataTable仍然没有填充任何东西。 到目前为止,我已经验证命令文本是否正确并且连接包含正确的连接字符串。 两者都在应用程序的其他部分中成功使用。 似乎没有例外......还有什么地方我应该寻找麻烦吗? 我是否错误地使用了 API?
谢谢!
I'm attempting to pull some data from a SQLite database so that I can populate a GridView in my GUI: here is the code that returns the DataTable:
DataTable table = new DataTable();
SQLiteDataAdapter adapter = new SQLiteDataAdapter(this.command.CommandText, this.connection);
adapter.Fill(table);
return table;
For some reason after calling adapter.Fill
, the DataTable is still not populated with anything. So far I've verified that the command text is correct and that the connection contains the correct connection string. Both are used successfully in other parts of the application. No exceptions seem to be thrown... Is there any place else I should be looking for trouble? Am I using the API incorrectly?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这看起来是正确的用法。
要检查的一件事 - 填充后你说数据表未填充。 您刚刚检查 Rows.Count 吗? 那么专栏呢? 如果 Fill 创建了与您的 SELECT 语句相匹配的列,但没有任何行,那么您就知道代码正在运行,但您的查询有问题,或者您没有访问您认为的同一数据库。
This looks like correct usage.
One thing to check -- after the fill you say the datatable is not populated. Were you just checking Rows.Count? What about columns? If the Fill creates columns to match your SELECT statement, but there aren't any rows, then you know the code is working but there's a problem with either your query, or you're not hitting the same database you think you are.
有没有一个构造函数可以让你直接传入命令?
Is there a constructor that lets you just pass in the command directly?