问题
What does this actually mean?
I am stepping through some code and when I look at the properties of my datareader under the locals window in vs2010, the DR.HasRows shows an error:
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 is a cursor and how do I make it scrollable? :)
回答1:
I got this error before and this is the solution:
bool hasRow = DR.Read();
if(hasRow)
{
//TODO
}
回答2:
A better solution would be to force the result set into being scrollable. Do it this way:
SqlCeDataReader dr = command.ExecuteResultSet(ResultSetOptions.Scrollable);
Read about what types of cursors there are here
回答3:
Just use a DR.read() in a while loop. If your query is set properly, you know it will only run once, but if you want to control it even further, simply use break after reading youd data:
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;
}
来源:https://stackoverflow.com/questions/7599994/sql-server-compact-does-not-support-calls-to-hasrows-property-if-the-underlying