Click here to Skip to main content
15,889,659 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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"

C#
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)
}
Posted
Updated 13-Sep-14 0:40am
v2
Comments
What is the issue here?
10923679 13-Sep-14 1:57am    
how to read each row from one table to another ?
and after getting matching fields..
if the amount of employee_table is more then it wont update .
if the amount of employee_table is same of less from amount of company_table
then that particular row will update .


i have update bulk.. but dont how how to update each row...
can you help me with this
George Jonsson 13-Sep-14 6:41am    
Is your problem the SQL syntax that should be used to update a row>
10923679 13-Sep-14 7:04am    
Yeah i want to know ..

How to read each row and compare with matching Fields with another table
OriginalGriff 13-Sep-14 7:01am    
And?
Where are you stuck?
What have you tried?
What help do you need?

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[^]
 
Share this answer
 
v2
Comments
10923679 13-Sep-14 8:30am    
Thank you. I will go through it.
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:
SQL
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
SQL
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

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.
 
Share this answer
 
Comments
10923679 13-Sep-14 12:05pm    
Okay.. Thanks a lot for ur suggestion.
If you are saying so.. Then how shall it do it using sp ?

Please share your process which will make the process fast n quick. I would like to follow that only..
OriginalGriff 13-Sep-14 12:16pm    
You know how to create an SP, don't you?
http://msdn.microsoft.com/en-gb/library/ms345415.aspx

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900