如何从表中读取每一行并与Asp.Net中的另一个表进行比较(Csharp) [英] How Do I Read Each Row From A Table And Compare With Another Table In Asp.Net(Csharp)
问题描述
使用company_table读取一行表emplyee_table
匹配(类似)
EmpID,Name,Amount_ID和年份
检查具有相同匹配的每行的金额EmpID,Name,Amount_ID和年份不超过company_table金额
Read one row of table emplyee_table with company_table
matching(similar)
EmpID, Name , Amount_ID and year
check the "amount" of each row having same matching EmpID, Name , Amount_ID and year doesn't exceed with company_table "amount"
if the amount of employee_table exceed company_table.. (if e.amt>c.amt)
{
validatiion- that row will not update
}
else if the amount of employee_table is same company_table (if e.amt=c.amt)
{
update that particular row into (company_details_table)
}
else if the amount of employee_table is same company_table (if e.amt<c.amt)
{
update that particular row into (company_details_table)
}
推荐答案
如果SQL命令是您的问题你可以从这里开始: SQL教程 [ ^ ]
具体更新命令: SQL UPDATE语句 [ ^ ]
对于c#部分,你应该查找MSDN SqlConnection [ ^ ]和 SqlCommand [ ^ ]
你会在那里找到一些例子。
还有很多其他来源: C#SqlCommand [ ^ ]
If SQL commands is your problem you can start here: SQL Tutorial[^]
Update command specifically: SQL UPDATE Statement[^]
For the c# part you should look up MSDN for SqlConnection[^] and SqlCommand[^]
You will find some examples there.
There are plenty of other sources too: C# SqlCommand[^]
好的。
我在网络上工作..在局域网中它将是..
它将逐一读取每一行..会有很多数据..在table1 n table2中。一旦找到匹配字段并检查table1的数量是否超过表2的数量,那么它将仅更新那些未超过该数量的行。
并且它在另一个表3中更新,列名称已经过验证。该金额已正确更新为该员工。
好的,这将是缓慢的。非常慢。
每次获取行都涉及一个局域网会话,在SQL端处理,数据返回到C#,在那里处理,另一次会话再次返回到SQL服务器。如果你做了很多行,那就太慢了。
用SQL做。
设置一个事务,并在其中做两个更新命令。
假设您有三张桌子:
Table1
id,amt,updates
Table2
id,t1Id,amt
表3
id,t1Id,已验证
然后这两个更新非常简单:
Alright.
I am working in a web based.. In a LAN it will be..
It will read each row one by one.. There will be many data.. In table1 n table2. Once it find the matching field and check the amount that amout of table1 is not exceeding amount of table 2 then it will update those rows only which has not exceeded the amount.
And it wi update in a another table 3 that column name as verified. That amount is correctly updated to those employee.
Ok, that will be slow. Horribly slow.
Each row fetch involves a lan conversation, processing on the SQL side, data back to C#, processing there, and another conversation back to the SQL server again. If you are doing many rows, that's pretty damn slow.
Do it in SQL.
Set up a transaction, and do two update commands inside it.
Assuming you have three tables:
Table1
id, amt, updates
Table2
id, t1Id, amt
Table3
id, t1Id, verified
Then the two updates are pretty trivial:
UPDATE t1
SET t1.updates = t1.updates + 1
FROM Table1 t1
JOIN Table2 t2 ON t1.id = t2.t1Id
JOIN Table3 t3 ON t1.id = t3.t1Id
WHERE t1.amt < t2.amt
和
And
UPDATE t3
SET t3.verified = 'Yes'
FROM Table1 t1
JOIN Table2 t2 ON t1.id = t2.t1Id
JOIN Table3 t3 ON t1.id = t3.t1Id
WHERE t1.amt < t2.amt
让SQL以最有效的方式解决这个问题 - 它非常擅长!
我设置了一个SP,在事务中包含那两个(所以如果它失败则没有任何改变)并且只是从C#执行它。
什么都没有留下SQL,以及处理由最擅长的软件完成。
Will let SQL work out the most efficient way to do that - and it's pretty good at it!
I'd set up an SP, containing those two inside a transaction (so if it fails there is nothing changed) and just execute that from the C#.
Nothing leaves SQL, and the processing is done by the software that's best at it.
这篇关于如何从表中读取每一行并与Asp.Net中的另一个表进行比较(Csharp)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!