这实际意味着什么?
我正在逐步完成一些代码,当我在vs2010的locals窗口下查看我的datareader的属性时,DR.HasRows显示错误:
HasRows '(DR).HasRows' threw an exception of type 'System.InvalidOperationException' bool {System.InvalidOperationException}
base {"SQL Server Compact does not support calls to HasRows property if the underlying cursor is not scrollable."} System.SystemException {System.InvalidOperationException}
WHat是一个游标,如何使其可滚动? :)
答案 0 :(得分:9)
我之前收到此错误,这是解决方案:
bool hasRow = DR.Read();
if(hasRow)
{
//TODO
}
答案 1 :(得分:1)
更好的解决方案是强制结果集可滚动。这样做:
SqlCeDataReader dr = command.ExecuteResultSet(ResultSetOptions.Scrollable);
了解有哪些类型的游标here
答案 2 :(得分:1)
只需在while循环中使用DR.read()即可。如果您的查询设置正确,您知道它只会运行一次,但如果您想进一步控制它,只需在读取您的数据后使用break:
while (DRder.Read())
{
//get your date from the reader.
//optional break, though it will do two things,
//1. ensure one record is returned
//2. Eliminate the need for the while loop to check again.
break;
}