SqlDataReader的不返回所有记录 [英] SqlDataReader does not return all records

查看:140
本文介绍了SqlDataReader的不返回所有记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到使用ADO.NET SqlDataReader的一个问题。当我直接运行在底层的SSMS中的存储过程 - 它返回的记录170万美元。当我运行一个有关VB.NET code,填补一个ADO.NET数据表 - 我也得到记录170万

I am experiencing a problem with ADO.NET SqlDataReader. When I run underlying stored procedure directly in SSMS - it returns 1.7 million of records. When I run a related VB.NET code that fills an ADO.NET DataTable - I also get 1.7 million of records.

但是当我运行一个循环来填充泛型列表像这样

But when I run a loop to fill a Generic list like this

While i_oDataReader.Read
   m_aFullIDList.Add(i_oDataReader.GetInt32(0))
End While

它返回少了很多记录,并且这一数字会有所不同。在循环结束时,如果我检查 m_aFullIDList.Count 是ca的是100000或500000等任何想法,为什么,以及如何解决它?谢谢!

It returns a lot less records and that number can vary. At the end of the loop if I check m_aFullIDList.Count it ca be 100000 or 500000 etc. Any idea why and how to fix it? Thanks!

推荐答案

由于基准由@Tim Schemlter指出,我发现选项CommandBehavior.SequentialAccess也为DataReader的创作。这解决了该问题。例如。而不是

Thanks to reference pointed by @Tim Schemlter I found the option "CommandBehavior.SequentialAccess" for DataReader creation. That fixed the issue. E.g. instead of

drReader = oCommand.ExecuteReader();

使用

drReader = oCommand.ExecuteReader(CommandBehavior.SequentialAccess);

和它工作正常。

这篇关于SqlDataReader的不返回所有记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆