|
-
Feb 6th, 2004, 11:42 PM
#1
Thread Starter
Lively Member
Syntax Error in Update Statement
VB Code:
Private Sub btnDeleteKeepInHistory_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDeleteKeepInHistory.Click
Dim objTrans As OleDb.OleDbTransaction
objCmd.CommandText = "INSERT INTO ExEmployee " & _
"([I/C Number], Name, Department, [P/C Number], [Date Joined], [Date Left], Reason) VALUES " & _
"('" & txtICNumber.Text & "', '" & txtName.Text & "', '" & txtDepartmentCode.Text & "', '" & txtPunchCardNumber.Text & "', #" & txtDateJoined.Text & "#, #" & txtDateLeft.Text & "#, '" & txtReason.Text & "')"
OleDbConnection1.Open()
objTrans = OleDbConnection1.BeginTransaction
objCmd.Transaction = objTrans
Try
objCmd.ExecuteNonQuery()
Response.Write("SQL1 Passed")
objCmd.CommandText = _
"UPDATE Employee SET Name=" & _
"'" & txtEmpty.Text & "' , " & _
"[IC Number] = '" & txtEmpty.Text & "' , " & _
"[Date Joined] = '" & txtEmpty.Text & "' , " & _
"[Confirm Letter] = '" & txtEmpty.Text & "' , " & _
"[Appointment Letter] = '" & txtEmpty.Text & "' , " & _
"Status = '" & txtEmpty.Text & "' , " & _
"Shift = '" & txtEmpty.Text & "' , " & _
"WHERE [P/C Number]='" & txtPunchCardNumber.Text & "' , "
objCmd.ExecuteNonQuery()
Response.Write("SQL2 Passed")
objTrans.Commit()
Catch ex As OleDb.OleDbException
objTrans.Rollback()
lblErrorMessage.Text = "Transaction Error...!"
TextBox1.Text = ex.Message
Return
Finally
OleDbConnection1.Close()
End Try
dgListEmployee.DataBind()
End Sub
Anyone can tell me what's wrong with my UPDATE statement, because MSG shows Syntax error in UPDATE statement.
-
Feb 7th, 2004, 04:35 AM
#2
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|