Dan*_*nte 3 c# datatable datarow dataset
我在C#中使用DataSet和DataTables.
我的第一个问题是如何将DataRow []对象转换为DataTable,我用这个链接解决了这个问题:
那么,我做的是以下内容:
// Gets the rows according to the relation
DataRow[] rows = someDataRow.GetChildRows("the_table_relation");
DataTable newDataTable = rows.CopyToDataTable<DataRow>();
Run Code Online (Sandbox Code Playgroud)
我使用的所有数据都在一个DataSet中,因此,我的问题是我的对象newDataTable不再包含对我的DataSet的引用(即newDataTable.DataSet等于null).
有没有办法进行转换而不会丢失对我的DataSet的引用?
希望可以有人帮帮我.
提前致谢
Jon*_*eet 10
想必你已经有一个DataTable?如果是这样,请使用以现有表作为参数的重载CopyToDataTable:
rows.CopyToDataTable<DataRow>(existingTable, LoadOption.Upsert);
Run Code Online (Sandbox Code Playgroud)
或者,你可以使用DataTableCollection.Add(DataTable)吗?
dataSet.Tables.Add(table);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
36007 次 |
| 最近记录: |