将数据表添加到数据集中的现有数据表 [英] Adding a datatable to an existing datable on a dataset

查看:73
本文介绍了将数据表添加到数据集中的现有数据表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个返回数据表的方法.我想将此数据表分配给数据集(.xsd文件)上的现有数据表.在数据集上,我有数据表A和数据表B.当我调用方法时,我想将返回的数据表分配给数据集上的数据表A.使用此数据集作为报告数据源.我该怎么做..?请帮助我...

I have a method returning a datatable. I want to assign this datatable to an existing datatable on a dataset(.xsd file).On dataset i have datatable A and datatable B.When i am calling the method the returned datatable i want to assign to datatable A on dataset.I am using this dataset as a report datasource.how can i do this..?Please help me...

推荐答案


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.


这篇关于将数据表添加到数据集中的现有数据表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆