I'm trying to update the position column in my access database but the problem is I'm having problem update that column while the rest of the column will not give out error message.
The error message: Syntax error in UPDATE statement, Microsoft JET database engine...
The code:
Dim myConnection As OleDbConnection = New OleDbConnection
Dim ds As New DataSet
Dim da As OleDbDataAdapter
Dim MaxRows As Integer
Dim i As Integer
Dim sql As String
Private Sub updateButton_Click(sender As Object, e As EventArgs) Handles updateButton.Click
Using myConnection = New OleDbConnection("Provider = Microsoft.ACE.OLEDB.12.0; Data Source =C:\LecturerDetail.mdb")
myConnection.Open()
Dim str As String
str = "UPDATE lecturer " & _
"SET [empName] = ?,[empId] = ?, [position] =?, [faculty] = ? " & _
" , [degree1] = ?, [degree2] = ?, [degree3] = ?,[degree] = ?, [empType] = ? " & _
" ,[icNo] = ?, [citizenship] = ?, [phoneNo] = ?, [email] = ?,[permitNo] = ? " & _
" , [permitStartDate] = ?, [permitEndDate] = ?, [pStatus] =?, [remark] =? " & _
" WHERE ([empId] = ?) "
Dim cmd As OleDbCommand = New OleDbCommand(str, myConnection)
cmd.Parameters.AddWithValue("@empName", nameTxt.Text)
cmd.Parameters.AddWithValue("@empId", empIdTxt.Text)
cmd.Parameters.AddWithValue("@position", positionComboBox.SelectedText)
cmd.Parameters.AddWithValue("@faculty", facultyComboBox.SelectedText)
cmd.Parameters.AddWithValue("@degree1", empDeg1.Text)
cmd.Parameters.AddWithValue("@degree2", empDeg2.Text)
cmd.Parameters.AddWithValue("@degree3", empDeg3.Text)
cmd.Parameters.AddWithValue("@degree", empDeg4.Text)
cmd.Parameters.AddWithValue("@empType", empTypeComboBox.SelectedText)
cmd.Parameters.AddWithValue("@icNo", icTxt.Text)
cmd.Parameters.AddWithValue("@citizenship", citizenshipComboBox.SelectedText)
cmd.Parameters.AddWithValue("@phoneNo", phoneTxt.Text)
cmd.Parameters.AddWithValue("@email", emailTxt.Text)
cmd.Parameters.AddWithValue("@permitNo", permitNoTxt.Text)
cmd.Parameters.AddWithValue("@permitStartDate", DateTimePicker1.Text)
cmd.Parameters.AddWithValue("@permitEndDate", DateTimePicker2.Text)
cmd.Parameters.AddWithValue("@pStatus", statusComboBox.Text)
cmd.Parameters.AddWithValue("@remark", remark.Text)
cmd.Parameters.AddWithValue("@empId", empIdTxt.Text)
Try
cmd.ExecuteNonQuery()
Dim cb As New OleDb.OleDbCommandBuilder(da)
ds.Tables("lecturer").Rows(i).Item(0) = empIdTxt.Text
ds.Tables("lecturer").Rows(i).Item(1) = nameTxt.Text
ds.Tables("lecturer").Rows(i).Item(2) = positionComboBox.Text
ds.Tables("lecturer").Rows(i).Item(3) = facultyComboBox.Text
ds.Tables("lecturer").Rows(i).Item(4) = empDeg1.Text
ds.Tables("lecturer").Rows(i).Item(5) = empDeg2.Text
ds.Tables("lecturer").Rows(i).Item(6) = empDeg3.Text
ds.Tables("lecturer").Rows(i).Item(7) = empDeg4.Text
ds.Tables("lecturer").Rows(i).Item(8) = empTypeComboBox.Text
ds.Tables("lecturer").Rows(i).Item(9) = icTxt.Text
ds.Tables("lecturer").Rows(i).Item(10) = citizenshipComboBox.Text
ds.Tables("lecturer").Rows(i).Item(11) = phoneTxt.Text
ds.Tables("lecturer").Rows(i).Item(12) = emailTxt.Text
ds.Tables("lecturer").Rows(i).Item(13) = permitNoTxt.Text
ds.Tables("lecturer").Rows(i).Item(14) = DateTimePicker1.Value
ds.Tables("lecturer").Rows(i).Item(15) = DateTimePicker2.Value
ds.Tables("lecturer").Rows(i).Item(16) = statusComboBox.Text
ds.Tables("lecturer").Rows(i).Item(17) = remark.Text
da.Update(ds, "lecturer")
ds.AcceptChanges()
myConnection.Close()
MsgBox("Record Updated")
Catch ex As Exception
MessageBox.Show(ex.Message & "-" & ex.Source)
End Try
End Using
End Sub
My code is to update the columns and allow user to navigate to the next record.
I'm new to visual basic so detail description and guidance are appreciated. Thanks. In addition, i'm trying to create auto notification system based on the dates. Anyone might enlighten me on which methods or applications to be used in visual basic to do it.