Question:
When Using SQL in VB6 to search a database Error is displayed " Data Type mismatch in criteria expression.?
jords
2012-09-11 10:38:38 UTC
I have a text box where The invoice number is entered to be used in the search for the record. - txtSearchID


Here is my code-

Private Sub cmdSearchID_Click()

Dim SearchID As String
SearchID = txtSearchID.Text
Set con = New ADODB.Connection
con.CursorLocation = adUseClient
con.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\BeanBag.mdb"

Set SalesRS = New ADODB.Recordset
SalesRS.Open "SELECT* FROM Sales Where InvoiceNo = '" & txtSearchID.Text & "'", con, adOpenKeyset, adLockOptimistic
Set DataGrid1.DataSource = SalesRS
End Sub

Please help? When I replace [ Where InvoiceNo = '" & txtSearchID.Text & "'",] with [Where InvoiceNo = '" 000001 & "'",] I obtain the required result, just having an issue with using the TextBox to provide the Search parameter.

Thank you
Five answers:
S Rahman
2012-09-11 12:46:51 UTC
Hi,



SalesRS.Open "SELECT* FROM Sales Where InvoiceNo = " & trim(txtSearchID.Text) & ", con, adOpenKeyset, adLockOptimistic



Hope it works for you
?
2016-07-27 19:27:00 UTC
It can be traditionally a trouble together with your the place clause. You're pronouncing "where 'something' equals 'some thing else'. These two values must be immediately comparable, both given that they are the same data variety (e.G. Each numbers), or they're close enogh for an implicit conversion. Double verify your whole '=' and make certain the 2 objects are the equal data type.
2014-09-05 21:01:51 UTC
hard step browse over a search engine it can help
Laurence I
2012-09-11 10:45:52 UTC
you did this at the start

SearchID = txtSearchID.Text

so why not do that again and use SearchID or some other STRING variable

txtSearchID.Text is probably NOT a STRING by TYPE even if it does contain one
TheMadProfessor
2012-09-12 07:40:10 UTC
txtSearchID.Text is just that - text. You have to convert that string to an integer value. That's why it worked when you simply plugged in 00001.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...