Click here to Skip to main content
15,894,405 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi i have a guid abcde and i have id in table guid i want to make an update but doesn works.


string cmd1 = "UPDATE Publisher SET checkid='"+ CheckBoxList1.SelectedValue.ToString() + "' WHERE idi=" + abcde + "";


abcde value is 1996c33b-786c-4acf-87c1-14c9c9fbc879


The error is: Incorrect syntax near 'c33b'.


Please help.
Posted
Updated 28-Nov-10 17:58pm
v3

Hi Prevas,
Why dont you use GUID as

C#
GUID.ToString().Substring(0,7)


or you can also use

C#
GUID.ToString().Replcae("-","")
;


This way you will not get any "-" during queries and hence can avoid such type of errors.



Anurag
 
Share this answer
 
Comments
Prevas 29-Nov-10 0:21am    
the idi in database is 1996c33b-786c-4acf-87c1-14c9c9fbc879 when i make with GUID.ToString().Replcae("-","")
it gives me this error:Incorrect syntax near 'c33b786c4acf87c114c9c9fbc879'.
:(
@nuraGGupta@ 29-Nov-10 0:29am    
check your "where" syntax, it is wrong.
It should be:

WHERE idi="+"'" + abcde + "'"+"";

Please check this way and inform if still the problem persists.
By the way, who is downvoting me here? [;P]
Prevas 29-Nov-10 0:44am    
there is no error but its not updating :(

dont worry my friend i will make it work somehow
@nuraGGupta@ 29-Nov-10 1:16am    
ok, this seems to be another problem. Do tell me what was the issue, when you correct it. I feel like checklistbox rebinding during the time of postback may be a cause.
First, you should never use unvalidated input from asp.net for a database query. Second, don't use string concatenation. You should use parameterized queries.
 
Share this answer
 
Comments
Prevas 29-Nov-10 0:22am    
I am just testing it first. if it works then i will put parameters
[no name] 29-Nov-10 7:07am    
Wrong answer! Do it right the first time.
Prevas 29-Nov-10 8:47am    
ok
WHERE idi=" + abcde + "";

Make sure abcde is of type GUID.
 
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