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

为君一笑 提交于 2019-12-10 17:24:03

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!