0
votes

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()
1
Use parameters to avoid sql injection and formatting issues. It would solve your problem, too, since Batch ID probably isn't a string value in the database. - LarsTech
The error is pretty much a catchall - usually the problem is a syntax error. - rheitzman
can you give me an example on how to do it? i just want to check if the batch id and product exist on the database. - NiewBiee2020

1 Answers

0
votes

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)