基于行和列从表复制到另一个 [英] Copy from table to another based on Row and column

查看:109
本文介绍了基于行和列从表复制到另一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从一个表复制到另一个表

我有2个数据表table1和table2

我想匹配参数名称并将第2和第2个值从table2复制到table1相同参数的新列(p90和p10)名称如何解决问题?



输入

table1

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  |
   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



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





<大>输出:

table1



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     |





添加评论:



Added from comment :

for (int i = 0; i < +table1.Rows.Count; i++) {
   string col = table1.Rows[i]["Par Name"].ToString() 
   if (table2.Columns.Contains(col)) {
      table1.Rows[i]["point90"] = table2.Rows[4]["col"].ToString(); //Error here col does not exits in current context
   }
}



[/ Edit]


[/Edit]

推荐答案

for (int i = 0; i < +table1.Rows.Count; i++) {



还有一个额外的 + table1 之前;不过没什么大不了的。




There is an extra + in front of table1; not a big deal, though.

string col = table1.Rows[i]["Par Name"].ToString()



这里有两个问题:

- 一个; 在行尾没有了

- 参数名称不应该是[参数名称]而不是[参数名称](根据帖子的其余部分)?



而且,最重要的是,因为您指向错误的行在同义词上是正确的:

哪个错误?你介意与我们分享吗?


Two problems here:
- a ; is missing at the end of the line
- should not the name of the parameter be ["Parameter Name"] instead of ["Par Name"] (according to the rest of your post)?

And, most important, as the line where you are pointing the error is synctatically correct :
which error? Would you mind sharing it with us?


foreach(table1.Rows中的DataRow dr1)

{

string para = dr1 [ Par Name]。ToString();

dr1 [point90] = table3.Rows [5] [para];

dr1 [point10] = table3.Rows [2] [para];

}
foreach (DataRow dr1 in table1.Rows)
{
string para = dr1["Par Name"].ToString();
dr1["point90"] = table3.Rows[5][para];
dr1["point10"] = table3.Rows[2][para];
}


这篇关于基于行和列从表复制到另一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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