Please im having a syntax error in my code. Please Help
When i click on the add button it give me syntax error in query expression "order Id" blah bla
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
Dim cmd As New OleDb.OleDbCommand
If con.State = ConnectionState.Closed Then
'open connection if it is not yet open
con.Open()
End If
cmd.Connection = con
'Checks whether you want to add new or update records
If OrdID.Tag & "" = "" Then
'Add new
'Add data to table
Try
cmd.CommandText = "INSERT INTO Sales(Order_Id, Order_Category, Order_Date, Order_Rate, Order_Quantity, Order_Amount) " & _
" VALUES(" & OrdID.Text & ",'" & OrdCat.Text & "','" & _
CStr(OrdDate.Text) & "','" & OrdRte.Text & "','" & _
OrdQty.Text & "','" & OrdAmt.Text & "')"
cmd.ExecuteNonQuery()
MsgBox("Record Sucessfully Created", MsgBoxStyle.Information)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End If
'Update data in table
Try
cmd.CommandText = "UPDATE Sales " & _
" SET Order_Id=" & OrdID.Text & _
", Order_Category='" & OrdCat.Text & "'" & _
", Order_Date='" & CStr(OrdDate.Text) & "'" & _
", Order_Rate='" & OrdRte.Text & "'" & _
", Order_Quantity='" & OrdQty.Text & "'" & _
", Order_Amount='" & OrdAmt.Text & "'" & _
" WHERE Order_Id='" & OrdID.Tag
cmd.ExecuteNonQuery()
MsgBox("Record Sucessfully Updated", MsgBoxStyle.Information)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
'Refresh data in list
RefreshDataGrid()
'Clear form
btnClear.PerformClick()
'Close connection
con.Close()
End Sub