Click here to Skip to main content
14,303,949 members
Rate this:
Please Sign up or sign in to vote.
See more:
I am trying to read data from a table in access database using query :

qryString = "SELECT * from Catalog WHERE (Catalog_ID = '" & txtCatalogID.Text & "')"

Dim dbCommand As OleDb.OleDbCommand = New OleDb.OleDbCommand(qryString, myConnection)

dataRdr = dbCommand.ExecuteReader


When I try to access the table with the above statement I get an exception
"Data type mismatch in criteria expression"
.

Catalog_ID field is numeric field in table Catalog. If I change the field type to Text then there is no problem. However I want to keep the data type for the field Catalog_ID as Numeric only.

Could someone please tell me where I am going wrong.

Thanks
Posted
Updated 16-May-15 0:10am
v2

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

You need to remove ['] around the numeric value, but (!!!) i have to warn you, because your code is SQL injection[^] vulnerable. Rather than it, use parametrized query:
qryString = "SELECT * from Catalog WHERE (Catalog_ID = @catid)"

Then you have to add parameter[^] to the collection[^].
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100