add two datatable in dataset

Posted by Venkatesh under ASP.NET on 4/26/2011 | Points: 10 | Views : 4405 | Status : [Member] | Replies : 1
Hi

i am having one dataset and one datatable.Dataset having 4 coulmns and datable having 1 coulmn.i want add this coulmn into dataset.

Thanks
Venkatesh.P




Responses

Posted by: Ndebata on: 4/26/2011 [Member] Starter | Points: 25

Up
0
Down
lets say ds is the dataset where you want to add a column to a table

DataTable dt2nd=new DataTable("SourceTableName");

ds.Tables[0].Columns.Add("Cloumn5");
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
if (dt2nd.Rows.Count > i)
ds.Tables[0].Rows[i]["Cloumn5"] = dt2nd.Rows[i]["ColumnName"];
}


Venkatesh, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response