开发者

SQL Server Compact does not support calls to HasRows property if the underlying cursor is not scrollable."

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 cur开发者_如何学Pythonsor and how do I make it scrollable? :)


I got this error before and this is the solution:

bool hasRow = DR.Read();
if(hasRow)
 {
    //TODO
 }


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


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; 

            }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜