Need some help with the code below. Getting and error at ExecuteNonQuery()
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btnRoomSave.Click
Dim con As New OleDbConnection
Dim cmd As New OleDb.OleDbCommand
cmd = New OleDbCommand(Command, con)
con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source='C:\PATIENT_O\PATIENT_O\Patient-O.accdb'"
cmd.CommandType = System.Data.CommandType.Text
cmd.Connection = con
con.Open()
cmd.CommandText = "INSERT INTO Rooms (RoomID, First Name, Middle Name, Last Name, Room Type, Amt/Day, Comments) VALUES ('@RoomID, @FirstName, @Middle Name, @Last Name, @Room Type, @Amt/Day, @Comments')"
'cmd.CommandText = "INSERT INTO [Rooms] (]RoomID], [First Name], [Middle Name], [Last Name], [Room Type], [Amt/Day], [Comments]) VALUES (" & txtRoomID.Text & ", '" & txtroomFName.Text & "', '" & txtroomMName.Text & "', '" & txtroomLName.Text & "','" & txtRoomtype.Text & "', '" & txtroomAmount.Text & "', '" & txtroomComment.Text & "')"
cmd.Parameters.AddWithValue("@RoomID", Val(txtRoomID.Text))
cmd.Parameters.AddWithValue("@FirstName", txtroomFName.Text)
cmd.Parameters.AddWithValue("@Middle Name", txtroomMName.Text)
cmd.Parameters.AddWithValue("@Last Name", txtroomLName.Text)
cmd.Parameters.AddWithValue("@Room Type", txtRoomtype.Text)
cmd.Parameters.AddWithValue("@Amt/Day", txtroomAmount.Text)
cmd.Parameters.AddWithValue("@Comments", txtroomComment.Text)
cmd.ExecuteNonQuery()
Try
MsgBox("Record Added")
Catch exceptionObject As Exception
MessageBox.Show(exceptionObject.Message)
Finally
con.Close()
End Try
End Sub