比较两个不同表中的值 [英] Comparing the values in two different tables

查看:83
本文介绍了比较两个不同表中的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi,
I have two tables in my Database say t1 which is used as a reference table and table t2 which need to be compared, I have a scenario like my previous method returns say row no A of t1  now i need to check Particular columns say gram,milligram and kilogram columns in t1 with the same columns in my t2 and need to check whether my t1 values are less than the t2 values for the Particular columns, If my previous methods returns more than 1 row i need to check the same for all the rows which it has returned at once,

how can i achieve this? I am using C# and SQL Ce 





我有什么试过:





What I have tried:

private void btnSearch_Click(object sender, EventArgs e)
       {
            object result = dbCon.ExecuteReader("SELECT  C.Type FROM  Material_Declaration AS M INNER JOIN Total_Chemicals_List AS C ON M.CAS_Number = C.CAS_Number and M.CAS_Number <> 'No CAS' WHERE (M.Part_Number_ID = '" + txtPart.Text + "') AND (C.Type IS NOT NULL) ");
            if (result != null)
            {
result = dbCon.ExecuteReader("SELECT  Substance_Mass,Substance_Percentage FROM Material_DeclarationAS M WHERE EXISTS (SELECT Mass_in_mg, Weight FROM  Total_Chemicals_ListAS C WHERE (M.Substance_Mass &lt; C.Mass_in_mg) and (C.Type = " + result.ToString() + ")");
If (result != null)
{
 ABC();
}

推荐答案

将表格放在两个数据表中并通过循环比较,参考

如何比较两个数据表并根据比较结果创建一个新的数据表(c#)| ASP.NET Fo朗姆酒 [ ^ ]
Get your tables in two datatables and compare it by looping, refer
How to compare two data tables and create a new data table based on the compared results (c#) | The ASP.NET Forums[^]


这篇关于比较两个不同表中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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