如何将数据表的列合并到数据集 [英] how to combine the columns of datatable to dataset
本文介绍了如何将数据表的列合并到数据集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要两个将数据表的两列合并到数据集,并想绑定到gridview.
我尝试通过以下两种方式进行操作,但它会将datable合并到具有不同表的数据集中.
i want two merge the two columns of datatable to dataset and want bind to gridview.
i try in following two ways but it merge datable to dataset with different table.
DataTable DtAudit = new DataTable("AUDIT");
DataSet ds = null;
ds.Tables[0].PrimaryKey = new DataColumn[] { ds.Tables[0].Columns["AR_Code"] };
DtAudit.PrimaryKey = new DataColumn[] { DtAudit.Columns["AR_Code"] };
DataSet dsNew = new DataSet();
dsNew.Merge(ds);
ds.Merge(DtAudit);
第二种方式
And the second way
DataTable DtAudit = new DataTable("AUDIT");
DataSet ds = null;
foreach(Datacloumn dc in DtAudit)
{
ds.Tables[0].columns.Add(dc)
}
推荐答案
不确定您要问的是什么,但是尝试使用表的Load
方法,看看它是否是您想要的.例如,
Not sure what you are asking, but try the Load
method of the table and see if it is what you want. For example,
oTable1.Load(oTable2.CreateDataReader())
这篇关于如何将数据表的列合并到数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文