OleDbDataAdapter.Fill()是否用实际数据填充DataTable? [英] Does OleDbDataAdapter.Fill() Fill DataTable with Actual Data?

查看:422
本文介绍了OleDbDataAdapter.Fill()是否用实际数据填充DataTable?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从DataTable创建对象,并且发现该过程在网络连接上花费的时间比在本地花费的时间要多得多.无论使用DataTable还是Reader,性能基本相同.

I'm creating objects from a DataTable, and I'm finding that the process takes a lot more time over a network connection than it does locally. The performance is basically the same whether I use a DataTable or Reader.

无论是通过网络还是本地,OleDbDataAdapter.Fill(dataTable)的执行速度都相对较快,但是对象构造存在巨大的时间差异.

The OleDbDataAdapter.Fill(dataTable) executes relatively quickly whether over the network or local, however there is a huge time difference with object construction.

我假设OleDbDataAdapter.Fill(dataTable)实际上用数据库中的数据填充了DataTable,但是我猜不是这样,因为在执行OleDbDataAdapter.Fill(dataTable)方法时构造时间变化如此之大相当 很快.

I assumed that OleDbDataAdapter.Fill(dataTable) actually filled the DataTable with the data from the database, but I'm guessing this is not the case since the construction time varies so widely while the OleDbDataAdapter.Fill(dataTable) method executes fairly quickly.

是否有人可以验证OleDbDataAdapter.Fill(dataTable)方法实际上并未填充任何数据,并且还可以提供有关从数据库中存储的数据构造对象的更有效方式的任何建议.谢谢,马特

Can someone verify that the OleDbDataAdapter.Fill(dataTable) method does not actually populate any data, and also perhaps offer any advice on a more efficient way of constructing objects from data housed in a database. Thanks, Matt

                var oda = new OleDbDataAdapter(query, con);
                var reportItemsDataTable = new DataTable();
                oda.Fill(reportItemsDataTable);

                foreach (var row in reportItemsDataTable.Rows)
                {
                    var itemRow = (DataRow)row;
                    ReportItemUIElements.Add(new ReportItemUIElement(new ReportItem(itemRow)));
                }

推荐答案

>有人可以验证OleDbDataAdapter.Fill(dataTable)方法实际上并未填充任何数据

>Can someone verify that the OleDbDataAdapter.Fill(dataTable) method does not actually populate any data

  DataAdapter确实确实将数据库中的数据加载到内存中的DataTable中,您可以通过在运行Fill后检查DataTable来轻松地进行验证.

 DataAdapters do actually load the data from the database into the DataTable in memory, which you can easily verify by examining the DataTable after running Fill.

>有关从数据库中存储的数据构造对象的更有效方法的建议

>advice on a more efficient way of constructing objects from data housed in a database

分析您的代码,以了解为什么要花这么长时间.从加载DataTable开始,以将数据库访问与对象构造分开.

Profile your code to see why it takes so long.  Start with the loading the DataTable to separate the database access from the object construction.

David


这篇关于OleDbDataAdapter.Fill()是否用实际数据填充DataTable?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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