假设你的表是这个样子的(代码仅供参考) table1(ID,主键;RuleID) table2(ID,主键,RuleID) using (SqlConnection con = new SqlConnection(“镇铅……”)) { con.Open(); SqlCommand cmd = new SqlCommand("select RuleID from table1 where ID="+你的ID,第一个表,con); string result = cmd.ExecuteScaler().ToString(); cmd.CommandText = "select RuleID from table1 where ID="+你历唤的ID,第二个表; string result2 = cmd.ExecuteScaler().ToString(); if(result.Equals(result2)) { cmd.CommandText="update 第二张表 set RuleID="+result+" where ID="第二张表的要修改的主键御烂好值"; cmd.ExecuteNonQuery(); } }