I need help in fixing this bug (Data type mismatch).Im using a datagrid to insert data to access database but get this error. I can update and delete during runtime but I cant insert data to database. Following is my code:

Try
    conn = New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Video Store\Video Store\DvDSystem.mdb")
    conn.Open()
    selectQuery = "SELECT DVDID FROM DVD WHERE DVDID = '" & txtDVDID.Text & "'"
    cmd = New OleDb.OleDbCommand(selectQuery, conn)
    dr = cmd.ExecuteReader
    'if successful
    If dr.Read Then
        MessageBox.Show("DVD id already exist!, Please enter different id", "Data Entry Error", MessageBoxButtons.OK)
        txtDVDID.Focus()
        conn.Close()
    Else
        conn = New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Video Store\Video Store\DvDSystem.mdb")
        'conn = New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data source=C:\Video Store\DvDSystem1.accdb")
        conn.Open()
        insertQuery = "INSERT INTO DVD VALUES(" & txtDVDID.Text & ",'" & txtTitle.Text & "', '" & txtProducer.Text & "','" & dtpReleaseDate.Text & "','" & cbocategory.Text & "','" & cboRating.Text & "','" & txtCopyCost.Text & "','" & txtRentalPrice.Text & "','" & txtCopyNumber.Text & "')"
        cmd = New OleDb.OleDbCommand(insertQuery, conn)
        icount = cmd.ExecuteNonQuery   (this is the line where i get data mismatch error)

Plz help

Are any of the columns used in that insert statement integers, double, floats, etc? If yes, you would need to parse the matching input from text to whatever the column type is.

Thanks a lot..it works like a charm.

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.