Click here to Skip to main content
15,905,238 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Professionals,

Can someone please tell me what the error with this statement is:

SQL
this.oleDbDataAdapter1.UpdateCommand.CommandText =
     string.Format("UPDATE Data SET input={0} , output={1} , price={2} WHERE lineName='{3}' AND dat=#{4}#"
          , "1"
          , "2"
          , "100"
          , "line1"
          , "01/01/2010");

this.oleDbDataAdapter1.UpdateCommand.ExecuteNonQuery();


I got a syntax error with Update statement Exception with this. I also tried it without string formatting but the problem still exists. The SELECT and INSERT commands are working fine but with UPDATE!!!???

Any idea?
Posted

Genius.Boy wrote:
I also tried it without string formatting but the problem still exists.


Well, I would start right there. Forget about string formatting. What is the error you get when you run it? Can you run the SQL directly on Management Studio or Query Analyzer? What happens when you run it? That may give you some clue to work on.
 
Share this answer
 
Comments
Genius.Boy 19-May-10 12:41pm    
First of all, thank you for reminding me with using Query Analyzer. I got the problem. I discovered that the Query Analyzer put brackets in the fields INPUT and OUTPUT. This really solved the problem.

But I am still wondering why the brackets are so important. Are these words (INPUT and OUTPUT) considered to be reserved words?

Any way, thank you very much.
Yusuf 19-May-10 13:10pm    
INPUT and OUTPUT are keywords. So you need to tell SQL you are using them as variable, field name or column name. If possible rename it to something else.
Try:
C#
string myUpdateString = "UPDATE Data SET input={0}, output={1}, price={2} WHERE lineName='{3}' AND dat='{4}'";

this.oleDbDataAdapter1.UpdateCommand.CommandText = string.Format(myUpdateString, "1", "2", "100", "line1", "01/01/2010");

this.oleDbDataAdapter1.UpdateCommand.ExecuteNonQuery();


If this does not work, just check using debugger what command is executing. (Put debugger at ExecuteNonQuery() line and see what is the command set.) Modify it what it should be (you can verify that running it in your databse.)
 
Share this answer
 
Comments
Genius.Boy 19-May-10 12:45pm    
Thank you for replying. I found where the problem exactly is. Look at my comment in the first answer.
Btw, single qoutations also gives error because the data type is DATE.

Thanks again.

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