【发布时间】:2015-07-16 07:30:17
【问题描述】:
我有两个具有相同名称/架构但具有不同值的表。 我需要找到具有相同主键(第一列)但值不同的行。 前任。 我的表:
id name age
1 ram 25
2 mohan 30
我的表:
id name age
3 harry 26
**1 ram 35**
3 tony 45
所以我需要 2 个表中的 2 行,值为 35。 它应该将整行作为数据表或数据行返回。 我正在使用 oracle 数据库。此解决方案需要 c# 代码。 它也应该适用于其他表的多个列值。 我的代码..
public OracleCommand getColumns(OracleConnection connection, DataTable table, int i, string tab, DataTable table3)
{
int columCount = table.Columns.Count;
string [] colArray = new string[columCount];
string pkey = table.Columns[0].ColumnName;
string pkeyValue = table.Rows[i][0].ToString();
string query2 = "SELECT * FROM " + tab +
" WHERE " + tab + "." + pkey + " = '" + pkeyValue + "'";
OracleCommand command = new OracleCommand();
int k = 0;
int X =0;
for(int j=1 ; j<colArray.Length;j++)
{
string column = table.Columns[j].ColumnName;
string columnValue = table.Rows[i][j].ToString();
string add = " OR " + tab + "." + column + " = '" + columnValue + "'";
query2 += add;
command.CommandText = query2;
command.CommandType = CommandType.Text;
command.Connection = connection;
var check = command.ExecuteNonQuery();
if (check == null)
{
k++;
}
else
X++;
}
return command;
}
【问题讨论】:
-
谢谢兄弟。我是新来的……
-
我不太了解你的目标 - 你能澄清你的问题吗?
-
所以你想得到一行 [1, ram, 25] 和一行 [1, ram, 35],因为 id=1 匹配,但年龄不匹配?
-
所以你需要 select id from tab1 t , tab2 w where t.id=w.id ?
-
我需要得到关注的价值..
标签: c# mysql oracle linq-to-sql