Quote:Copying from one table to another
I have 2 datatable table1 and table2
I want match the Parameter names and copy the 5th and 2nd value from table2 to table1 into a new column(p90 and p10) for same parameter Name how to approach the problem ?
Input
table1
|Parameter Name | Lower limit |Upper limit |P90 point|P10 point|
Diff_IC[1] | 1.5 | 2.5 | | |
Prog_IC[2] |-10 | 10000000 | | |
Nam_IC[3] |-64 |64 | | |
ADCI_N[1 ] |-0.8 | -0.1 | | |
table2
Diff_IC[1] | Prog_IC[2] | Nam_IC[3] | ADCI_N[1 ] |
-0.145712003 -0.146583006 -0.165715003 -0.126583006
-0.137499005 -0.137592003 -0.157493005 -0.117592003
-0.142690003 -0.143250003 -0.132693003 -0.153250003
-0.139434993 -0.140459001 -0.129434933 -0.150459001
-0.147183999 -0.148519993 -0.117183459 -0.138519993
-0.137183999 -0.134519993 -0.517183459 -0.338519993
Output:
table1
|Parameter Name| Lower limit| Upper limit | P90 point |P10 point |
Diff_IC[1] | 1.5 | 2.5 |-0.147183999 |-0.137499005 |
Prog_IC[2] |-10 | 10000000 | -0.148519993 | -0.137592003 |
Nam_IC[3] |-64 |64 | -0.117183459 | -0.157493005 |
ADCI_N[1 ] |-0.8 | -0.1 | -0.138519993 | -0.117592003 |
Loading

VulpesPosted Mar 10, 2014, 11:02 AM
Jignesh TrivediPosted Mar 12, 2014, 12:02 AM
hi,
try....
DataTable table1 = new DataTable();
table1.Columns.Add("Parameter Name");
table1.Columns.Add("Lower limit");
table1.Columns.Add("Upper limit");
table1.Rows.Add(new object[] { "Diff_IC[1]", "1.5", "2.5" });
table1.Rows.Add(new object[] { "Prog_IC[2]", "-10", "10000000" });
table1.Rows.Add(new object[] { "Nam_IC[3]", "-64", "64" });
table1.Rows.Add(new object[] { "ADCI_N[1]", "-0.1", "-0.1" });
DataTable table2 = new DataTable();
table2.Columns.Add("Diff_IC[1]");
table2.Columns.Add("Prog_IC[2]");
table2.Columns.Add("Nam_IC[3]");
table2.Columns.Add("ADCI_N[1]");
table2.Rows.Add(new object[] { "-0.145712003", "-0.146583006", "-0.165715003", "-0.126583006" });
table2.Rows.Add(new object[] { "-0.137499005", "-0.137592003", "-0.157493005", "-0.117592003" });
table2.Rows.Add(new object[] { "-0.142690003", "-0.143250003", "-0.132693003", "-0.153250003" });
table2.Rows.Add(new object[] { "-0.139434993", "-0.140459001", "-0.129434933", "-0.150459001" });
table2.Rows.Add(new object[] { "-0.147183999", "-0.148519993", "-0.117183459", "-0.138519993" });
table2.Rows.Add(new object[] { "-0.137183999", "-0.134519993", "-0.517183459", "-0.338519993" });
table1.Columns.Add("P90 point");
table1.Columns.Add("P10 point");
foreach (DataRow drow in table1.Rows)
{
drow["P90 point"] = table2.Rows[1][drow[0].ToString()];
drow["P10 point"] = table2.Rows[3][drow[0].ToString()];
}
hope this will help you.
Farhan ShariffPosted Mar 11, 2014, 8:20 AM
Farhan ShariffPosted Mar 10, 2014, 11:01 AM
{
string col = table1.Rows[i]["Par Name"].ToString()
if(table2.Columns.Contains(col))
{
table1.Rows[i]["point90"] =table2.Rows[4]["col"].ToString();//Error here
}
}
Farhan ShariffPosted Mar 10, 2014, 10:49 AM
VulpesPosted Mar 10, 2014, 10:32 AM