DataReader与DataTable [英] DataReader Vs DataTable

查看:77
本文介绍了DataReader与DataTable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不太了解.net。最近,当我和我的朋友谈话时,他提出了他在办公室遇到的一个小痘痘。他必须处理100万条记录。首先,他使用填充了100万条记录的数据表,然后循环查看记录,检查一些业务逻辑。具有百万记录成本内存的数据表也会循环数据表消耗更多时间。然后为了对此进行排序,他切换到datareader。现在程序工作得很好。我怀疑是数据处理器连接导向吗?它是从数据库中一次只获取一条记录吗?如果是这样,对于百万条记录它必须进行数百万次往返,这不是最优的吗?或者,我不能先在内存中取10000(watever可行数)记录并处理它然后再接受10000等等......如果是不好的逻辑?

i dont know .net very much. Recently when i talked to my friend he put forward a scnerio he encountered in his office.
he has to deal with 1 million records. first he used datatable which is filled with that 1 million records and he loops through the records
to check some business logic. Datatable with million records costs memory also looping the datatable consumes more time. Then to sort this out he switches to datareader. Now program works fine.my doubts are
is dataerader connection oriented? is it fetching only one record at a time from database? if so for million records it must do million roundtrips, isn't it optimal?
alternatively, couldnt i take first 10000(watever the feasible number) records in memory and process it then take another 10000 and so on..would that be bad logic?

推荐答案

逻辑上,通过良好的应用程序设计,您可以在批处理SQL语句中对数据应用业务逻辑避免完全检索数据或仅检索WHERE子句中与特定条件匹配的数据,而不是所有行。在某些情况下,某些情况下是不可能的。这取决于你需要达到的目标。在DataReader的情况下,是的,它保持连接打开并提供快速只读,仅向前游标,我相信它会缓存一些数据,除非您在调用ExecuteReader方法创建它时指定SingleRow选项。但是您对此光标没有太多控制权。


这篇关于DataReader与DataTable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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