简体   繁体   English

如何将行添加到数据集 c# 中的现有数据表?

[英]how add row to existing Datatable within dataset c#?

I am adding row/s to multiple Datatable then through my program I am adding these Datatable to Dataset what I am trying to do and I need to know now is我正在向多个Datatable添加行,然后通过我的程序将这些Datatable添加到Dataset我正在尝试做的事情,我现在需要知道的是

how to add row/s to one of these existing Datatable within existing Dataset ?如何行/ s添加到这些现有Datatable现有内Dataset

The class DataSet directly supports merging data in the form of DataRow or DataTable. DataSet 类直接支持以DataRow 或DataTable 的形式合并数据。 Query for your DataSet object and perform whatever operations you require.查询您的 DataSet 对象并执行您需要的任何操作。

public void Merge(DataRow[] rows, bool preserveChanges, MissingSchemaAction missingSchemaAction);
public void Merge(DataRow[] rows);
public void Merge(DataTable table, bool preserveChanges, MissingSchemaAction missingSchemaAction);
public void Merge(DataSet dataSet, bool preserveChanges, MissingSchemaAction missingSchemaAction);
public void Merge(DataSet dataSet);
public void Merge(DataSet dataSet, bool preserveChanges);

You could try something like this:你可以尝试这样的事情:

DataSet dataSet = new DataSet("DataSetName");
dataSet.Tables.Add("TableName");

var tableIndex = dataSet.Tables.IndexOf("TableName");
dataSet.Tables[tableIndex].Rows.Add(someDataRow);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM