Psst! Did you know DevelopmentNow is a mobile web site design agency?

Contact us for help mobilizing your site, or to sign up for our beta Mobile Web SDK!
all groups > dotnet ado.net > july 2009 >

dotnet ado.net : ASP.NET DataAdapter/CommandBuilder Syntax Error


babe_jt NO[at]SPAM hotmail.com
7/28/2003 12:46:12 PM
I am updating an Access 2000 database using ASP.NET. I pass a
datatable to a function in a DLL that updates the database with a
DataAdapter. When I run the program it crashes when updating and gives
the error: "Syntax Error in INSERT INTO Statement". I'm wondering what
I can do to fix it.

Private Sub SaveWork()
'Create an instance of a class to perform DB operations....
Dim objWork as new Work()
Dim dr As DataRow
Dim dtUpdate As New DataTable()
'return template for blank row
dtUpdate = objWork.GetAllWork(True)
dr = dtUpdate.NewRow
With dr 'set info in the datatable with values in textbox
fields
.Item("PersonID") = CInt(Session("PersonID"))
.Item("ProjectID") = intProjectID
.Item("Position") = txtPosition.Text.Trim
.Item("Sector") = txtSector.Text.Trim
.Item("Hours") = dblHours
.Item("Description") = txtDescription.Text
.Item("Date") = strDate
.Item("Temp") = True
End With
dtUpdate.Rows.Add(dr) 'Adding the new record to the datatable
objWork.SaveWork(dtUpdate, intProjectID)
End Sub


The function in the Work.vb class....

Public Function SaveWork(ByVal dtUpdate As DataTable, ByVal
ProjectID As Integer) As Boolean
OpenDB()
Dim da As New OleDbDataAdapter("SELECT * FROM WorkLog", con)
Dim cb As New OleDbCommandBuilder(da)
da.InsertCommand = cb.GetInsertCommand
da.Update(dtUpdate) '!!!!!!!!!!!!!!Crashes on this
line!!!!!!!!!!!!!!
CloseDB()
Return True
Marina
7/28/2003 4:22:07 PM
Looks like you are using some reserved words as column names. Try setting
the QuotePrefix and QuoteSuffix properties of the commandbuilder to "[" and
"]" respectively.

[quoted text, click to view]

davidsc NO[at]SPAM online.microsoft.com
7/28/2003 8:24:44 PM

This error often occurs if you're using a reserved word for
at least one of your column names. In such scenarios, you need
to delimit the column names. Try adding the following code:

...
Dim cb As New OleDbCommandBuilder(da)
cb.QuotePrefix = "["
cb.QuoteSuffix = "]"

I hope this information proves helpful.

David Sceppa
Microsoft
This posting is provided "AS IS" with no warranties,
and confers no rights. You assume all risk for your use.
© 2003 Microsoft Corporation. All rights reserved.
Emmad
7/2/2009 12:41:10 AM
Thank you sir for your help, although I am not the person who posted the question, I benifited from your reply 6 years later!
Cool.
Its amazing what people can accomplish if they help one another.

From http://www.developmentnow.com/g/7_2003_7_0_0_124383/ASP-NET-DataAdapterCommandBuilder-Syntax-Error.htm

Posted via DevelopmentNow.com Groups
AddThis Social Bookmark Button