C#中对两个表的数据进行对比

C#中对两个表的数据进行对比,第1张

DataTable c =new DataTable ()

c.columns.add("pass",typeof(string))

foreach(DataRow dr1 in a.rows)

{

DataRow [] dtemp = b.select("pass="+dr1["pass"].tostring())

if(dtemp.Length>0)

{

DataRow drNew = c.NewRow()

drNew ["pass"] = dtemp[0]["pass"]

c.rows.add(drnew)

}

}

dataGridView.source = c//此处根据实际需求来

//未经测试,大概思路吧,你也可以不用b.select,b表也用foreach(),如

foreach(DataRow dr1 in a.rows)

{

foreach(DataRow dr2 in b.rows){

// do something

}

}

UPDATE aps_tailor_instruction_detail_rec o, (SELECT a.tailorAssemblyLineId,a.tailorAssemblyLineCode,a.deptId,c.name tailorAssemblyLineName,b.id productionSubPlanDetailId,a.id productionSubPlanId,a.planNumber

FROM aps_production_sub_plan a,aps_production_sub_plan_detail b,md_tailor_assembly_line c WHERE a.id=b.productionSubPlanId  AND a.tailorAssemblyLineId=c.id 

AND b.id=79751 AND a.factoryId=46 AND a.disabled=0) n

SET o.tailorAssemblyLineId = n.tailorAssemblyLineId, o.tailorAssemblyLineCode = n.tailorAssemblyLineCode,o.deptId = n.deptId,o.tailorAssemblyLineName = n.tailorAssemblyLineName,

o.productionSubPlanId=n.productionSubPlanId,o.subPlanNumber=n.planNumber,o.productionSubPlanDetailId=n.productionSubPlanDetailId

WHERE instructionNumber IN ('CZ22010136','CZ22010137','CZ22010140') AND factoryId=46 AND disabled=0 AND size='170/92A'

AND o.productionSubPlanId=5572

意思:

判断 FGH列数据,在左边数据是否存在?

如果存在,则在数据库对应的数据行,D列写入 25

如果不存在,就把新的数据,写到数据库最后1行?


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/10702207.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-10
下一篇 2023-05-10

发表评论

登录后才能评论

评论列表(0条)

保存