Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello friend,

I am having problem retrieving ole object binary data from access database into picture box,

Table_name: Bio_data_ND1
i have a unique column called: regno
then column where the picture reside: picpath


actual i did a little work, but honestly it misbehaved. i used this codes:


VB
Private Sub display_result_ND1()
       Try

Dim adp As New OleDb.OleDbDataAdapter("select * FROM Bio_data_ND1 WHERE regno='" & TxtSearch.Text & "'", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\..\ResultPrc.mdb;Persist Security Info=True")
            Dim ds As New DataSet
            adp.Fill(ds, "Bio_data_ND1")
            Dim bytes() As Byte = ds.Tables("Bio_data_ND1").Rows(0).Item("picpath")
            Dim img As Image = Image.FromStream(New System.IO.MemoryStream(bytes))
            PictureBox2.Image = img


        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
end sub


but the WHERE clause is not working, whenever i try selecting it gives me only the last record stored in the database,

i dont know if the is a little mistake that i need to correct

if any please help.

thanks.
Posted
Updated 15-Aug-15 8:26am
v2
Comments
[no name] 15-Aug-15 14:27pm    
"regno" suggests that it's a numeric field. Is it? If so, why are you treating it as if it were a string?
@sunusi1 15-Aug-15 14:50pm    
actually regno is not a numeric value, rather it is declared as short text (i.e. varchar) variable
[no name] 15-Aug-15 15:41pm    
Well there's your second problem then. Whatever you are typing into the textbox does not match anything. Your primary problem is using string concatenation to construct your sql query.
@sunusi1 15-Aug-15 17:35pm    
yes i know it doesn't match anything but i have a search button that the picture will display if i click on the search button

but the problem is that what ever the regno i put in the searchBox it return the last record in the database. even though i used WHERE clause, but the result is same as i didn't use it
[no name] 15-Aug-15 21:41pm    
Okay... and? What is it that you expect someone to tell you? Debug your code, find the problem and fix it. We can't debug your code for you. We don't have access to your database. And you apparently don't listen.

1 solution

No matter of regno data type, you should use something like this:
SQL
select * FROM Bio_data_ND1 WHERE regno=?

because of sql injection[^]. Then call this command with: OleDbParameterCollection.AddWithValue Method[^]


Please, see similar question[^].
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900