如果基础游标不可滚动,SQL Server Compact 不支持调用 HasRows 属性。”

发布于 2024-12-07 09:35:35 字数 447 浏览 0 评论 0原文

这实际上意味着什么?

我正在单步执行一些代码,当我在 vs2010 中的本地窗口下查看数据读取器的属性时,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 是光标,如何使其可滚动? :)

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? :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

友欢 2024-12-14 09:35:35

我之前遇到过这个错误,这是解决方案:

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

I got this error before and this is the solution:

bool hasRow = DR.Read();
if(hasRow)
 {
    //TODO
 }
云醉月微眠 2024-12-14 09:35:35

更好的解决方案是强制结果集可滚动。这样做:

SqlCeDataReader dr = command.ExecuteResultSet(ResultSetOptions.Scrollable);

此处了解光标类型

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

り繁华旳梦境 2024-12-14 09:35:35

只需在 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; 

            }

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; 

            }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文