Click here to Skip to main content
15,902,447 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
Any one please give me some ideas update query
SqlCommand cmd2 = new SqlCommand("update sales set  empnames=@empnames+'" + comboBox1.Text +"',categories=@categories, weight=@weight,per=@per,wastage=@wastage,customer=@customer,party=@party,amtcst=@amtcst,amtparty=@amtparty,amtfinal=@amtfinal where date=@date", con2);
In the above query empnames add 2 times in database it meas 
EX : 
Empnames column : ramram, I want stored single name only. Give me some ideas.


What I have tried:

Update query problem for datagridview values updating time
Posted
Updated 26-Nov-16 6:19am
Comments
OriginalGriff 26-Nov-16 11:38am    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
Use the "Improve question" widget to edit your question and provide better information.
Boopalslm 26-Nov-16 11:57am    
HariHari 1 chain 2 2 2 0.04 2 0.130 5 -4.87
Hari 2 chain 3 3 3 0.09 3 0.130 5 -4.87

This is my update qury
SqlCommand cmd2 = new SqlCommand("update sales set empnames=@empnames+'" + comboBox1.Text + "', date=@date, categories=@categories, weight=@weight,per=@per,wastage=@wastage,customer=@customer,party=@party,amtcst=@amtcst,amtparty=@amtparty,amtfinal=@amtfinal where date=@date", con2);

See empnames names cell in first row empnames add 2 times
How to solve this problem.

1 solution

At a guess - and since you don't seem to want to provide actual information that's all it can be - your combobox contains the empname, and the @empnames parameter contains it as well. Or the @empnames parameter contains it twice.

We can't tell, because we can't read your code, or see anything other than exactly what you type.
So use the debugger, look at the exact data you are sending to SQL and it shoudl be obvious. We can't do that for you...

But don't do that. If you are aware of parameterised queries, then why are you not using them throughout, instead of risking SQL Injection by concatenating strings?
 
Share this answer
 
v2

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