如何在1个数据集中添加3个数据集值 [英] How to add 3 dataset values in 1 dataset

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

问题描述

你好朋友,



请帮助我,



我有三个数据集,我想要将三个数据集值绑定到一个数据集中,并将此数据集绑定到gridview。



给我任何解决方案。

解决方案

< blockquote>对于组合来自多个数据集的数据,所有数据集必须具有相同的结构。

 DataSet ds1 =  new 数据集(); 
DataSet ds2 = new DataSet();
DataSet ds3 = new DataSet();

// 此处填写三个数据集的代码

DataSet ds = new DataSet();
DataTable dt = ds1.Tables [ 0 ]。克隆();
ds.Tables.Add(dt);

foreach (DataRow dr in ds1.Tables [ 0 ]。行)
ds.Tables [ 0 ]。ImportRow(dr);

foreach (DataRow dr in ds2.Tables [ 0 ]。行)
ds.Tables [ 0 ]。ImportRow(dr);

foreach (DataRow dr in ds3.Tables [ 0 ]。行)
ds.Tables [ 0 ]。ImportRow(dr);

// ds将包含所有三个数据集ds1,ds2,ds3的第一个数据表的数据。将ds绑定到gridview


如果所有数据集在列名称和列数方面相同,则可以使用合并功能/>




ds1.merge(ds2)


Hello Friends,

Please help me,

I have three datasets and i want to bind three dataset values into one dataset and bind this dataset to gridview.

Give me any solution.

解决方案

For combining data from multiple datasets, all datasets must have same structure.

DataSet ds1 = new DataSet();
DataSet ds2 = new DataSet();
DataSet ds3 = new DataSet();

//Code to fill three datasets here

DataSet ds = new DataSet();
DataTable dt = ds1.Tables[0].Clone();
ds.Tables.Add(dt);

foreach (DataRow dr in ds1.Tables[0].Rows)
    ds.Tables[0].ImportRow(dr);

foreach (DataRow dr in ds2.Tables[0].Rows)
    ds.Tables[0].ImportRow(dr);

foreach (DataRow dr in ds3.Tables[0].Rows)
    ds.Tables[0].ImportRow(dr);

//ds will have data of first datatable of all three datasets ds1,ds2,ds3. Bind ds to gridview


You can use Merge function if all the dataset are identical in-terms of column Name & No. of column

Like
ds1.merge(ds2)


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

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