如何增加一条数据表到另一个数据表数据表

2023-09-04 02:33:21 作者:老师,借根烟

我想增加一条数据表到另一个数据表。我看到了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数据集,得到DataSet中的数据表,然后使用合并法合并数据表。

I could could usa 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.

推荐答案

合并需要一个数据表,加载需要一个IDataReader的 - 所以这取决于你的数据层,您可以访问,使用所需的方法。我的理解是,负载将在内部调用合并,但不是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.