Hi my problem is that When trying to insert a statement into an MSAccess file I get this message: Data type mismatch in criteria expression

Below are my codes. Im using vb.net 2.0

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim sql As String
        Dim officer As String
        Dim contactperson As String
        Dim posting As String
        Dim idate As String
        Dim tel As String
        Dim broughby As String
        Dim takenby As String
        Dim brand As String
        Dim systemunit As String
        Dim sn1 As String
        Dim monitor As String
        Dim sn2 As String
        Dim printer As String
        Dim sn3 As String
        Dim others As String
        Dim sn4 As String
        Dim preliminaryreport As String
        Dim Cn As OleDb.OleDbConnection
        Dim myCom As OleDb.OleDbCommand
        Cn = New OleDb.OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Hardware.mdb")
        officer = TextBox1.Text
        contactperson = TextBox2.Text
        posting = TextBox3.Text
        idate = TextBox16.Text
        tel = TextBox17.Text
        broughby = TextBox4.Text
        takenby = TextBox5.Text
        brand = TextBox6.Text
        systemunit = TextBox7.Text
        sn1 = TextBox8.Text
        monitor = TextBox9.Text
        sn2 = TextBox10.Text
        printer = TextBox11.Text
        sn3 = TextBox12.Text
        others = TextBox13.Text
        sn4 = TextBox14.Text
        preliminaryreport = TextBox15.Text
        sql = "INSERT INTO repair (officer, contactperson, posting, idate, tel, broughby, takenby, brand, systemunit, sn1, monitor, sn2, printer, sn3, others, sn4, preliminaryreport) VALUES ('" & TextBox1.Text & "', '" & TextBox2.Text & "', '" & TextBox3.Text & "', '" & TextBox16.Text & "', '" & TextBox17.Text & "', '" & TextBox4.Text & "', '" & TextBox5.Text & "', '" & TextBox6.Text & "', '" & TextBox7.Text & "', '" & TextBox8.Text & "', '" & TextBox9.Text & "', '" & TextBox10.Text & "', '" & TextBox11.Text & "', '" & TextBox12.Text & "', '" & TextBox13.Text & "', '" & TextBox14.Text & "', '" & TextBox15.Text & "')"
        myCom = New OleDb.OleDbCommand(sql, Cn)
        MessageBox.Show("Records Accepted")
    End Sub

Please help me find the error Thanks.

Recommended Answers

All 4 Replies

Please use code tags

its hard to see them all..

i think your code is ok..maybe its about your inputs..
your inputs must be suitable with database criteria,,like date..

but i don't understand why u assignment value from textboxes to variables but u never using variables in select statment.

I have configure the database to accept all fields as TEXT. Only for date and Tel it is as short date and number respectively. But still having the same problem.

Its working now ive changed the datatype in the database.

Thanks for your help

great yousha..
thats what i mean..your input must be suitable with database criteria(data type)..
ok..then u can mark this thread as solved..:)

Be a part of the DaniWeb community

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