且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将数据表添加到数据集中的现有数据表

更新时间:2023-11-30 22:37:28


DataTable dt = SomeMethodReturnDataTable();
YourDataSet ds = new YourDataSet();


将DataTable添加到DataSet中:


Add DataTable into DataSet:

ds.Tables.Add(dt)


或如果ds.Tables["A"]中的列与dt相同,则可以循环各行和列,并将dt中的值加载到ds.Tables["A"]中.


or If the columns inside ds.Tables["A"] is same with dt, then you can loop each rows and columns and load the value from dt into ds.Tables["A"].

int c = -1;
foreach (DataRow dr in dt.Rows)
{
    c++;
    ds.Tables["A"].Rows.Add();
    foreach (DataColumn dc in dt.Columns)
    {
        ds.Tables["A"].Rows[c][dc.ColumnName] = dr[dc.ColumnName];
    }
}


Didnt准确地回答了您的问题,请详细说明.
Didnt got your question exactly, please elaborate more.