Results 1 to 2 of 2

Thread: Syntax Error in Update Statement

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2002
    Location
    Malaysia
    Posts
    124

    Syntax Error in Update Statement

    VB Code:
    1. Private Sub btnDeleteKeepInHistory_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDeleteKeepInHistory.Click
    2.         Dim objTrans As OleDb.OleDbTransaction
    3.         objCmd.CommandText = "INSERT INTO ExEmployee " & _
    4.             "([I/C Number], Name, Department, [P/C Number], [Date Joined], [Date Left], Reason) VALUES " & _
    5.             "('" & txtICNumber.Text & "', '" & txtName.Text & "', '" & txtDepartmentCode.Text & "', '" & txtPunchCardNumber.Text & "', #" & txtDateJoined.Text & "#, #" & txtDateLeft.Text & "#, '" & txtReason.Text & "')"
    6.         OleDbConnection1.Open()
    7.         objTrans = OleDbConnection1.BeginTransaction
    8.         objCmd.Transaction = objTrans
    9.         Try
    10.             objCmd.ExecuteNonQuery()
    11.             Response.Write("SQL1 Passed")
    12.  
    13.             objCmd.CommandText = _
    14.             "UPDATE Employee SET Name=" & _
    15.             "'" & txtEmpty.Text & "' , " & _
    16.             "[IC Number] = '" & txtEmpty.Text & "' , " & _
    17.             "[Date Joined] = '" & txtEmpty.Text & "' , " & _
    18.             "[Confirm Letter] = '" & txtEmpty.Text & "' , " & _
    19.             "[Appointment Letter] = '" & txtEmpty.Text & "' , " & _
    20.             "Status = '" & txtEmpty.Text & "' , " & _
    21.             "Shift = '" & txtEmpty.Text & "' , " & _
    22.             "WHERE [P/C Number]='" & txtPunchCardNumber.Text & "' , "
    23.             objCmd.ExecuteNonQuery()
    24.             Response.Write("SQL2 Passed")
    25.             objTrans.Commit()
    26.         Catch ex As OleDb.OleDbException
    27.             objTrans.Rollback()
    28.             lblErrorMessage.Text = "Transaction Error...!"
    29.             TextBox1.Text = ex.Message
    30.             Return
    31.         Finally
    32.             OleDbConnection1.Close()
    33.         End Try
    34.         dgListEmployee.DataBind()
    35.     End Sub

    Anyone can tell me what's wrong with my UPDATE statement, because MSG shows Syntax error in UPDATE statement.


  2. #2
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950
    Couple possibilities...
    You seem to have a space after the single quotes at the end of the .texts, between the single quote and the comma.
    You have Name= rather than Name =.
    Not sure either of those make a difference.
    Are all your fields text in the db? I.e., is [Date Joined] a date field? if it is, you'd have to cast the .text to a Date and use # instead of '. That would probably raise a type mismatch error, though.
    And the main one, you have a comma following the TextPunchCard.text in your WHERE clause.

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