Problem with sql query

mounir_az

Member
Joined
Jan 11, 2009
Messages
18
Programming Experience
1-3
Good evening

I am trying to create an application in visual basic 2005 with sql server.
I use a barcode reader to read the data.
when I run a search query it for the barcode no result displayed.
here is my request.

Dim cmd As New SqlCommand ("select * from t_produit WHERE [code_barre] = '" & cb.Text & "'", con)
On Error Resume Next
dr = cmd.ExecuteReader
If dr.Read = True Then
refprod.Text = dr (0)
pu.Text = dr (5)
qstock.Text = dr (8)
qt.Text = 1
des.Text = dr (3)
End If

Here is an example of a barcode search: àà)àé(''H
 
First, look into parameterized queries. Its easier to read, and it will not fail when quotations are in cb.Text.

Second, update your error handling. I'm not even sure what On Error Resume Next does, but I know its out of date. Use Try..Catch.

Do you know if the data is being returned, but just not being displayed to the user? My guess is that no data is being returned at all.
 
I put the bar code according ABCD for a product for testing the application.
when I run the search it myself out the result, but if the bar code contains special characters like àà) AE (H'', no result is displayed.
 
Back
Top