Tinten Fruelda
New member
- Joined
- Jul 31, 2011
- Messages
- 2
- Location
- Valenzuela City, Philippines
- Programming Experience
- Beginner
I'm trying to insert a new record in my database but my query can't execute because of this error "Data type mismatch in criteria expression" although I'm basing my code from a book. I'm new to this, so hopefully someone could help me.
This is the code:
Private Sub b1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles b1.Click
Try
If (txt1.Text <> "" AndAlso txt2.Text <> "") Then
ReservationsAdapter.InsertCommand.CommandText = _
"INSERT INTO Reservations(FirstName, LastName, Birthdate, ContactNo, Occupation, Address ) " & _
"VALUES( '" & txt2.Text & "' , '" & txt1.Text & "' , '" & txt3.Text & "' , '" & txt4.Text & "' , '" & txt5.Text & "' , '" & txt6.Text & "')"
ReservationsConnection.Open()
MsgBox("Connection Open")
ReservationsAdapter.InsertCommand.ExecuteNonQuery()
MsgBox("Query Executed")
Else
MsgBox("Please fill up the form")
End If
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Sub
End Class
This is the code:
Private Sub b1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles b1.Click
Try
If (txt1.Text <> "" AndAlso txt2.Text <> "") Then
ReservationsAdapter.InsertCommand.CommandText = _
"INSERT INTO Reservations(FirstName, LastName, Birthdate, ContactNo, Occupation, Address ) " & _
"VALUES( '" & txt2.Text & "' , '" & txt1.Text & "' , '" & txt3.Text & "' , '" & txt4.Text & "' , '" & txt5.Text & "' , '" & txt6.Text & "')"
ReservationsConnection.Open()
MsgBox("Connection Open")
ReservationsAdapter.InsertCommand.ExecuteNonQuery()
MsgBox("Query Executed")
Else
MsgBox("Please fill up the form")
End If
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Sub
End Class