Hi all,
Hi i have got a problem with the system i am creating on VB using Microsft Access. I have this error that keeps coming up when I debug my system. I am trying to add data in the database. I cant seem to find the solution to this error.
**An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll
**Additional information: Syntax error in INSERT INTO statement.****
If anyone can see what is wrong and please let me know. Thank you.
Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
Dim cmd As New OleDb.OleDbCommand
If Not cnn.State = ConnectionState.Open Then
'The line of code below opens the connection to the database if it isnt open
cnn.Open()
End If
cmd.Connection = cnn
'Check whether to add new or update
If Me.txtItemID.Tag & "" = "" Then
'Add new
'The line of coding below adds data to table
cmd.CommandText = "INSERT INTO Product ([Item ID], [Item Name], [Item Type], [Quantity], [Min Shelf Stock], [Purchase Price], [Note]) " & _
" VALUES (" & Me.txtItemID.Text & ",'" & Me.txtItemName.Text & "','" & _
Me.cboItemType.Text & "','" & Me.txtQuantity.Text & "','" & _
Me.txtMinShelfStock.Text & "','" & Me.txtPurchasePrice.Text & "','" & _
Me.txtNote.Text & "')"
cmd.ExecuteNonQuery()
Else
'Update data in the table
cmd.CommandText = "UPDATE Product " & _
" SET Item ID=" & Me.txtItemID.Text & _
", Item Name='" & Me.txtItemName.Text & "'" & _
", Item Type='" & Me.cboItemType.Text & "'" & _
", Quantity='" & Me.txtQuantity.Text & "'" & _
", Min Shelf Stock='" & Me.txtMinShelfStock.Text & "'" & _
", Purchase Price='" & Me.txtPurchasePrice.Text & "'" & _
", Note='" & Me.txtNote.Text & "'" & _
" WHERE Item ID=" & Me.txtItemID.Tag
cmd.ExecuteNonQuery()
End If
'Refresh data in list
RefreshData()
'Clear the form
Me.btnClear.PerformClick()
'The code below closes the connection to the database
cnn.Close()
End Sub