Private Sub Button11_Click(sender As Object, e As EventArgs) Handles Button11.Click
        Dim sqlquery As String = "INSERT INTO firstfloor_house_rent (datee,amt) VALUES ('" & DateTimePicker8.Text & "', " & TextBox24.Text & ")"
        Dim sqlcommand As New OleDbCommand
        With sqlcommand
            .CommandText = sqlquery
            .Connection = conn
        End With
        ans = sqlcommand.ExecuteNonQuery()
        If (ans = True) Then
            'message added
            MessageBox.Show("Sucessfully added", "Sucess", MessageBoxButtons.OK)
        Else
            MessageBox.Show("failed to add record", "Error!!!", MessageBoxButtons.OK)   '' error

        End If
    End Sub

what is data type mismatch in this query. it gives data type mismatch in criteria expression.. plz help...

Recommended Answers

All 3 Replies

Member Avatar for Rahul47

1) You might want to check your query again.
Dim sqlquery As String = "INSERT INTO firstfloor_house_rent (datee,amt) VALUES ('" & DateTimePicker8.Text & "', " & TextBox24.Text & ")"

here you forgot to use '' for textbox24.text (String data should be used with single quotes in SQL query)

2) Your data might be mismatching here.
ans = sqlcommand.ExecuteNonQuery() If (ans = True) Then

As type returned by ExecuteNonQuery is bool i.e 1 or 0 so you might want to compare it with 1 or 0 in If Condition.

3) Free Advice: Better to use parametrized query.

textbox24 hold integer data n data type is also same in access.
thanx rahul for reply.. plz can u modify this code using parametrized query because i dont have much knowledge of parametrized query...

You can find an example here

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.