Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hi,

am getting Syntax error in update query.

can any one help me.

C#
cmd.CommandText = "UPDATE SystemInfo SET" + " UserName='" + UserName + "', UserDomainName='" + UserDomainName + "',UserMachineName='" + UserMachineName + "',UserIP='" + UserIP + "', UserOsVersion='" + UserOsVersion + "',UserSystemDirectory='" + UserSystemDirectory + "',UserCurrentDirectory='" + UserCurrentDirectory + "', ProcessorName='" + ProcessorName + "', ProcessMnufacturer='" + ProcessMnufacturer + "',ProcessorID='" + ProcessorID + "',ProcessorDescription='" + ProcessorDescription + "',ProcessorVersion='" + ProcessorVersion + "',ProcessorStatus='" + ProcessorStatus + "',ProcessorDeviceId='" + ProcessorDeviceId + "', OSCaption='" + OSCaption + "',OSSerialNumber='" + OSSerialNumber + "',OSManufacturer ='" + OSManufacturer + "',OSVersion='" + OSVersion + "', OSStatus='" + OSStatus + "',OSName='" + OSName + "', BiosName='" + BiosName + "',BiosVersion='" + BiosVersion + "',BiosSerialNumber='" + BiosSerialNumber + "', BiosManufacturer='" + BiosManufacturer + "',BiosCurrentlanguage='" + BiosCurrentlanguage + "', BiosStatus='" + BiosStatus + "Where UserName=" + UserName;



Thanks Regards
sam.198979
Posted
Comments
Prasad_Kulkarni 17-Jun-13 6:12am    
Can you show your table design?
[no name] 17-Jun-13 6:13am    
"any one help me", sure use a parameterized query instead like you should be using anyway and your exception will likely go away and you get the extra added benefit of avoiding SQL injection attacks.
Mike Meinz 17-Jun-13 6:28am    
You are missing several apostrophes. That said, it is a best practice to use the SQLParameter Class rather than concatenated string queries. Queries using the SQLParameter class perform better and are protected from SQL Injection Attacks.

See SQLParameter Class

1 solution

Last Statement

, BiosStatus='" + BiosStatus + "Where UserName=" + UserName;

should be like
, BiosStatus='" + BiosStatus + "' Where UserName='" + UserName+"'";

Added space and single quote before where keyword.
Please test yor query properly as it contain lot of variables involved.
Its always nice to use Parameters instead.
 
Share this answer
 

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