如何将一个数据表附加到另一个数据表 [英] How to append one DataTable to another DataTable
问题描述
我想将一个 DataTable 附加到另一个 DataTable.我看到 DataTable 类有两个方法;加载(IDataReader)"和合并(数据表)".从文档中,如果存在行,两者似乎都将传入数据与现有数据表合并".我将在数据访问层进行合并.
I would like to append one DataTable to another DataTable. I see the DataTable class has two methods; "Load(IDataReader)" and "Merge(DataTable)". From the documentation, both appear to 'merge' the incoming data with the existing DataTable if rows exist. I will be doing the merge in a data access layer.
我可以使用 IDataReader
并使用 Load 方法来合并数据表.或者我可以使用 IDataReader
加载数据集,从数据集中获取数据表,然后使用 Merge 方法合并数据表.
I could use an IDataReader
and use the Load method to merge the DataTables. Or I could load a DataSet using the IDataReader
, get the DataTable from the DataSet, and then use the Merge method to merge the DataTables.
我想知道是否有人可以告诉我使用哪种方法是正确的?
I was wondering if someone could tell me which is the proper method to use?
或者,如果您对如何完成此任务有不同的建议,请告诉我.
Alternatively, let me know if you have a different suggestion on how to accomplish this task.
推荐答案
Merge 需要一个 DataTable,Load 需要一个 IDataReader - 因此根据您的数据层允许您访问的内容,使用所需的方法.我的理解是 Load 会在内部调用 Merge,但不能 100% 确定.
Merge takes a DataTable, Load requires an IDataReader - so depending on what your data layer gives you access to, use the required method. My understanding is that Load will internally call Merge, but not 100% sure about that.
如果您有两个数据表,请使用合并.
If you have two DataTables, use Merge.
这篇关于如何将一个数据表附加到另一个数据表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!