Mt91
Mt91

Reputation: 1

data type mismatch in criteria expression(VB)

I seem to keep on getting the 'data type mismatch in criteria expression' error whenever i try to read in information from an access database, the data from within the database is being added to a listview.. Here is the following code:

 POStable.Clear()

    connection1.ConnectionString = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source=Shop.mdb"
    connection1.Open()
    POSAdapter = New OleDb.OleDbDataAdapter("Select * from items where barcode = '" & txtBarcode.Text & "'", connection1)
    CommandBuilder = New OleDb.OleDbCommandBuilder(POSAdapter)
    POSAdapter.Fill(POStable)             ' ****
    connection1.Close() 


    If POStable.Rows.Count = 0 Then
        MsgBox("Item does not exist")
    Else
        Dim objListItem As ListViewItem
        objListItem = ListViewPOS.Items.Add(POStable.Rows(0)(1).ToString)
        objListItem.SubItems.Add(1)
        objListItem.SubItems.Add("£" & (POStable.Rows(0)(2).ToString))
    End If 

The part above in BOLD is where i get the error. Ive connected to a database which contains one table called items. In that table there is just one row and 4 columns used for testing: barcode, item, price and quantity.

I was hoping if someone could help me explain why i have the error? Thanks

Upvotes: 0

Views: 218

Answers (1)

Jadeja RJ
Jadeja RJ

Reputation: 1014

Try This if your textbox contains illigal characters

POSAdapter = New OleDb.OleDbDataAdapter("Select * from items where barcode = [" & txtBarcode.Text & "]", connection1)

Upvotes: 1

Related Questions