Syntax error in update statement - novice question

Discussion in 'ASP .Net' started by sean, Dec 2, 2003.

  1. sean

    sean Guest

    Hi,

    I am trying to update an access database using an SQL statement, I keep
    getting an syntax error in update statment. I am passing in strChkBoxValue
    as a string value which is declared in another function. Could someone help
    me fix my code.

    Sean


    Dim oComm As OleDbDataAdapter
    Dim sConn As String
    Dim oDataSet As New DataSet
    Dim word as string

    'Build the connection string
    sConn = "Provider=Microsoft.Jet.OLEDB.4.0;"
    sConn += "Data Source =" & Server.MapPath("email.mdb") & ";"
    sConn += "Persist Security Info=False"


    Dim strSQL as String = _
    "Update members Set Email='" & _
    strChkBoxValue & "', " & _
    "' WHERE email='" & cstr(strChkBoxValue)



    Dim oConn as New OleDBConnection(sConn)
    Dim objCmd as New OLEDBCommand(strSQL, oConn)

    oConn.open
    objCmd.ExecuteNonQuery()
    oConn.Close
     
    sean, Dec 2, 2003
    #1
    1. Advertising

  2. sean

    Gerald Guest

    Could you post the response.Write of your SqlString.
    But it appears it is false. Too many single quotes and comma.
    So one reason could be this.
    Yours is :
    Dim strSQL as String = "Update members Set Email='" & strChkBoxValue & "', '
    WHERE email='" & cstr(strChkBoxValue)

    Dim strSQL as String = "Update members Set Email='" & strChkBoxValue & "'
    WHERE email='" & cstr(strChkBoxValue) & "'"

    Second is what the point to change the value of the email only when the
    email is equal to the new value. It wont change anything as the new value
    equals the old one.

    G


    "sean" <> wrote in message
    news:...
    > Hi,
    >
    > I am trying to update an access database using an SQL statement, I keep
    > getting an syntax error in update statment. I am passing in strChkBoxValue
    > as a string value which is declared in another function. Could someone

    help
    > me fix my code.
    >
    > Sean
    >
    >
    > Dim oComm As OleDbDataAdapter
    > Dim sConn As String
    > Dim oDataSet As New DataSet
    > Dim word as string
    >
    > 'Build the connection string
    > sConn = "Provider=Microsoft.Jet.OLEDB.4.0;"
    > sConn += "Data Source =" & Server.MapPath("email.mdb") & ";"
    > sConn += "Persist Security Info=False"
    >
    >
    > Dim strSQL as String = _
    > "Update members Set Email='" & _
    > strChkBoxValue & "', " & _
    > "' WHERE email='" & cstr(strChkBoxValue)
    >
    >
    >
    > Dim oConn as New OleDBConnection(sConn)
    > Dim objCmd as New OLEDBCommand(strSQL, oConn)
    >
    > oConn.open
    > objCmd.ExecuteNonQuery()
    > oConn.Close
    >
    >
     
    Gerald, Dec 2, 2003
    #2
    1. Advertising

  3. You're missing the last single quote after the words "' WHERE email='" &
    cstr(strChkBoxValue)

    --
    HTH,
    Kevin Spencer
    ..Net Developer
    Microsoft MVP
    Big things are made up
    of lots of little things.


    "sean" <> wrote in message
    news:...
    > Hi,
    >
    > I am trying to update an access database using an SQL statement, I keep
    > getting an syntax error in update statment. I am passing in strChkBoxValue
    > as a string value which is declared in another function. Could someone

    help
    > me fix my code.
    >
    > Sean
    >
    >
    > Dim oComm As OleDbDataAdapter
    > Dim sConn As String
    > Dim oDataSet As New DataSet
    > Dim word as string
    >
    > 'Build the connection string
    > sConn = "Provider=Microsoft.Jet.OLEDB.4.0;"
    > sConn += "Data Source =" & Server.MapPath("email.mdb") & ";"
    > sConn += "Persist Security Info=False"
    >
    >
    > Dim strSQL as String = _
    > "Update members Set Email='" & _
    > strChkBoxValue & "', " & _
    > "' WHERE email='" & cstr(strChkBoxValue)
    >
    >
    >
    > Dim oConn as New OleDBConnection(sConn)
    > Dim objCmd as New OLEDBCommand(strSQL, oConn)
    >
    > oConn.open
    > objCmd.ExecuteNonQuery()
    > oConn.Close
    >
    >
     
    Kevin Spencer, Dec 2, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sean
    Replies:
    1
    Views:
    597
    Cowboy \(Gregory A. Beamer\)
    Oct 20, 2003
  2. compuglobalhypermeganetz0r

    adapter update problem Syntax error in INSERT INTO statement.

    compuglobalhypermeganetz0r, Dec 8, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    831
    compuglobalhypermeganetz0r
    Dec 8, 2003
  3. Mark Sandfox
    Replies:
    1
    Views:
    3,398
    Mark Sandfox
    May 7, 2004
  4. Replies:
    1
    Views:
    6,076
    Nick Malik [Microsoft]
    Aug 12, 2005
  5. Paul
    Replies:
    16
    Views:
    205
    Jayme Pechan
    Aug 31, 2005
Loading...

Share This Page