0

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

Edited by Reverend Jim: fixed code formatting

2
Contributors
2
Replies
14
Views
3 Years
Discussion Span
Last Post by mbowenitj
1

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.