How to select "Amount" column from dt1 by dt2 "Name " column and add to dt2 ?
DataTable dt1 = new DataTable();
dt1.Columns.Add("Name",typeof(String));
dt1.Columns.Add("Surname",typeof(String));
dt1.Columns.Add("Amount",typeof(Int32));
dt1.Rows.Add("Mike","Michael",5);
dt1.Rows.Add("Tom", "Alice", 4);
dt1.Rows.Add("Jon", "Miri", 3);
dt1.Rows.Add("John", "Michael", 10);
DataTable dt2 = new DataTable();
dt2.Columns.Add("Name", typeof(String));
dt2.Columns.Add("Amount",typeof(Int32));
dt2.Rows.Add("Mike","");
dt2.Rows.Add("Tom", "");
dt2.Rows.Add("Jon", "");
dt2.Rows.Add("John", "");
Thanks in advance.
VulpesPosted Mar 30, 2013, 3:58 PM
Notice that since Amount is an int column, when adding rows to dt2, you'll need to use an int default value (say 0) rather than "":
Posted Mar 30, 2013, 4:18 PM