Telephone:
01273 552955

More contact details

 

Knowledgebase Categories:

Database Development

PC General

Programming

Servers and Networks

Web Development

Web Hosting

Knowledgebase

Syntax Error on ADO.NET Update (16 Jun 2006)

Recently we hit a strange problem on a VB.NET 2005 application. Stripped down to its bare essentials the code was as follows:

Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\LinkCheck\db.mdb"
Dim sql As String
Dim adapter As OleDbDataAdapter
Dim cmdBuilder As OleDbCommandBuilder
Dim dsLinks As New DataSet
Dim rowcount As Integer

sql = "SELECT * FROM [Link] WHERE [IncludeInSearch] = True"
adapter = New OleDbDataAdapter(sql, connectionString)
cmdBuilder = New OleDbCommandBuilder(adapter)
adapter.Fill(dsLinks, "Link")

With dsLinks.Tables("Link")
  For rowcount = 0 To .Rows.Count - 1
    .Rows(rowcount).Item("IsIndexed") = "yes"
  adapter.Update(dsLinks, "Link")
  Next
End With

The Update command failed with "Syntax error (missing operator) in query expression". Now in this scenario that update command is built automatically by OleDbCommandBuilder. My immediate thought was that there was a conflict between some of the field names and Access reserved words. I changed any that looked to be possible candidates, but the problem remained.

After further research I discovered and added the following two lines:
cmdBuilder.QuotePrefix = "["
cmdBuilder.QuoteSuffix = "]"
These set the beginning and ending character to use when specifying database objects whose names contain characters such as spaces or reserved tokens. This resolved the problem.


Comments

THANK YOU (all caps)

thats all...i guess the rest can be guessed

Posted by: someone (05 Sep 2006 16:43)

Thanks a lot ......I was looking for your answer ....Thank you a lot......

Posted by: roninMBV (16 Oct 2006 16:55)

Thanks! This saved me a lot of trouble and grief!

Posted by: Terry (29 Nov 2006 20:29)

Thanks! This save dme a load of trouble trying to track down an error!

Posted by: Steve (29 Nov 2006 20:31)

Post a comment

Name:

Comments: (you may use HTML tags for style)

The information is provided 'as is'. It has worked for us, but it may not work for you, so you use it at your own risk. We can't enter into any correspondance about anything recorded here but please feel free to leave a comment.

Geographical coverage: AlphaOne Computing Services provides a range of small business computer support and I.T. services throughout Sussex, including Brighton, Hove, Shoreham, Worthing, Steyning, Burgess Hill, Haywards Heath, Crawley, Lewes, Newhaven, Seaford, Uckfield and Eastbourne.