NiewBiee2020 NiewBiee2020 - 4 months ago 9
Vb.net Question

Data type mismatch on ms access database

I have a problem on my program. it says "Additional information: Data type mismatch in criteria expression." and the error was throw to

rs.Fill(dt)
here's my code

con.Open()

Dim dt As New DataTable("tbl_Stock")
Dim rs As New OleDb.OleDbDataAdapter("Select * from [tbl_Stocks] WHERE [Product] ='" & lbPro.Text & "' AND [Batch ID] = '" & txtID.Text & "'", con)
Dim ve As String
rs.Fill(dt)


ve = CStr(dt.Rows.Count)
rs.Dispose()
con.Close()

Answer

Most likely, Batch ID is numeric, thus no quotes:

Dim rs As New OleDb.OleDbDataAdapter("Select * from [tbl_Stocks] WHERE [Product] ='" & lbPro.Text & "' AND [Batch ID] = " & txtID.Text & "", con)