Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I have a program that updates a Access database through the use of a dataset, dataadapter, and connection. I let the dataadapter create all my statements, and I built in from the dataset. My problem is when I do an update I get the message "Syntax error in update statement". I copied the sql update statement into Access, plugged in the data, and it ran fine. So I'm not sure why there is a syntax error. The update statement is:

 

UPDATE Vehicle SET Make = ?, Model = ?, VehicleID = ?, VINNum = ?, Year = ? WHERE (VehicleID = ?) AND (Make = ? OR ? IS NULL AND Make IS NULL) AND (Model = ? OR ? IS NULL AND Model IS NULL) AND (VINNum = ? OR ? IS NULL AND VINNum IS NULL) AND (Year = ? OR ? IS NULL AND Year IS NULL)

 

Most of the code is generated and the changes on the form are put into a new dataset and then the command to update the database is:

 

OleDbDataAdapter1.Update(ChangedRows)

 

Any ideas what could be wrong? This has worked fine in other programs I have used it in. Thanks!

Posted

Maybe adjusting the parentheses to be more clear:

 

UPDATE Vehicle
 SET Make = ?,
   Model = ?,
   VehicleID = ?,
   VINNum = ?,
   Year = ?
 WHERE VehicleID = ?
   AND ((Make = ?) OR (? IS NULL AND Make IS NULL))
   AND ((Model = ?) OR (? IS NULL AND Model IS NULL))
   AND ((VINNum = ?) OR (? IS NULL AND VINNum IS NULL))
   AND ((Year = ?) OR (? IS NULL AND Year IS NULL))

 

Other than that, I'd suggest taking a look at the values of all the ?s and making sure there are no errors arising from those.

  • *Experts*
Posted

Surround all the columns/tables with brackets. Some words, like Year, are reserved words. For example:

SELECT [Year], ...

instead of

SELECT Year, ...

 

-ner

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...