shootsnlad Posted October 20, 2004 Posted October 20, 2004 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! Quote
fizzled Posted October 20, 2004 Posted October 20, 2004 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. Quote
*Experts* Nerseus Posted October 22, 2004 *Experts* Posted October 22, 2004 Surround all the columns/tables with brackets. Some words, like Year, are reserved words. For example: SELECT [Year], ... instead of SELECT Year, ... -ner Quote "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
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.