SQlDataReader 不更新其结果集

发布于 2024-09-27 15:46:49 字数 601 浏览 0 评论 0原文

我有一个用以下命令填充的 sqldatareader:

string cmdlookup = String.Format("Select {0} from {1}", strSourceName, strSourceTable);
  SqlCommand sqlcom = new SqlCommand(cmdlookup, con);
SqlDataReader rdrsource = cmd.ExecuteReader();


            while (rdrsource.Read())
            {


                this.lstSourceValues.Add(System.Convert.ToString(rdrsource[strSourceName]));



            }
            rdrsource.Close();

程序中其他地方有一个函数可以修改此表。我已经验证它确实更新了有问题的表。该表现在有 11 个值。

此查询的结果永远不会改变。它始终返回 5 行,即使应用程序中其他位置的函数已明确更新了表。下面几行我也关闭了连接。

这个东西是以某种方式缓存的吗?为什么查询不更新?

I have a sqldatareader populated with this command:

string cmdlookup = String.Format("Select {0} from {1}", strSourceName, strSourceTable);
  SqlCommand sqlcom = new SqlCommand(cmdlookup, con);
SqlDataReader rdrsource = cmd.ExecuteReader();


            while (rdrsource.Read())
            {


                this.lstSourceValues.Add(System.Convert.ToString(rdrsource[strSourceName]));



            }
            rdrsource.Close();

There is a function elsewhere in the program to modify this table. I have verified that it does indeed update the table in question. The table now has 11 values.

This results of this query NEVER CHANGES. It always returns 5 rows, even though a function elsewhere in the application has clearly updated the table. A few lines below I close the connection, too.

Is this thing cached somehow? Why doesn't the query update?

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

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

发布评论

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

评论(1

花开雨落又逢春i 2024-10-04 15:46:49

我能够解决这个问题。问题是,当我调用 .Close() 和/或 .Dispose() 时,它并没有真正摆脱该对象。

相反,我需要切换到使用 using 结构。由于某种原因,当我使用 using 构造时,它肯定会关闭并删除该对象。

它没有改变,因为我不断获得对象的相同内存表示。

I was able to resolve the issue. The problem was that when I was calling .Close() and/or .Dispose(), it wasn't really getting rid of the object.

Instead, I needed to switch to using a using construct. For some reason, when I used the using construct, it definitely closed deleted the object.

It didn't change because I was continually getting the same in-memory representation of the object.

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