Results 1 to 3 of 3

Thread: [RESOLVED] update error

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    779

    Resolved [RESOLVED] update error

    I can't get this update to work. This is the error I get.
    Syntax error (missing operator) in query expression

    VB.NET Code:
    1. Private cnxnString As String = ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\SPECTRUM\YMCA\db1.mdb")
    2.     Private cnxn As New System.Data.OleDb.OleDbConnection(cnxnString)
    3.     Private sql As New System.Data.OleDb.OleDbCommand
    4.     Private myDataAdapter As New System.Data.OleDb.OleDbDataAdapter("SELECT * FROM [DEDUPED]", cnxn)
    5.     Private myDataAdapter2 As System.Data.OleDb.OleDbDataAdapter
    6.     Private cmdBuilder As New System.Data.OleDb.OleDbCommandBuilder(myDataAdapter)
    7.     Private tblDEDUPED As New DataTable
    8.     Private tblCOMBINED As New DataTable
    9.  
    10.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    11.         Me.Cursor = Cursors.WaitCursor
    12.         myDataAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKey
    13.  
    14.         myDataAdapter.Fill(tblDEDUPED)
    15.  
    16.         Dim myUnitID As String = Nothing
    17.         Dim myUpdateSQL As String = Nothing
    18.         myDataAdapter.UpdateCommand = cmdBuilder.GetUpdateCommand
    19.  
    20.         For Each dbRow As DataRow In tblDEDUPED.Rows
    21.             myUnitID = dbRow.Item("UNIT ID")
    22.             myDataAdapter2 = New System.Data.OleDb.OleDbDataAdapter("SELECT * FROM [COMBINED] WHERE [UNIT ID] = '" & myUnitID & "'", cnxn)
    23.             myDataAdapter2.Fill(tblCOMBINED)
    24.  
    25.             For j As Integer = 0 To tblCOMBINED.Rows.Count - 1
    26.                 dbRow.Item("NAME1") = "TEST"
    27.             Next j
    28.             myDataAdapter.Update(tblDEDUPED)
    29.             tblCOMBINED.Clear()
    30.         Next
    31.  
    32.         myDataAdapter.Dispose()
    33.         myDataAdapter2.Dispose()
    34.         cnxn.Close()
    35.         cnxn.Dispose()
    36.  
    37.         Me.Cursor = Cursors.Default
    38.         MsgBox("DONE!")
    39.     End Sub

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    779

    Re: update error

    figured it out. there were spaces in the field names. not good.

  3. #3
    Frenzied Member MaximilianMayrhofer's Avatar
    Join Date
    Aug 2007
    Location
    IM IN YR LOOP
    Posts
    2,001

    Re: [RESOLVED] update error

    If UNIT ID is numeric, then you should not be using the single quotes. It should simply be:

    "SELECT * FROM COMBINED WHERE [UNIT ID] = " & myUnitID

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width