Click here to Skip to main content
15,849,129 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hai I have little confusion. I am developing a family card program for my church. I want to show the photos of all members of a family in a form. please help me what I do...

VB
Dim cmd As New SqlCommand("Select MemPhoto from FamilyDetails where FamilyID=@FamilyID", sqlcon)
        cmd.Parameters.Add("@FamilyID", SqlDbType.Int).Value = txtsearchbox.Text
        Dim dt As New DataTable
        Dim adp As New SqlDataAdapter(cmd)
        adp.Fill(dt)


There are seven picture boxes on my form. But I am little confused how to bind data to picture boxes...
please help.....
Posted
Updated 29-Jul-15 1:04am
v2

1 solution

Hi First download and save that picture in temp folder from sql based on select query and in picture box imagelocation url u give that temp folder path with picture name.

VB
PictureBox1.ImageLocation = "C:\inetpub\wwwroot\ccp\temp\a.ico"


I think u store ur picture stored in binary format in sql.


VB
Dim cn As New SqlConnection()
            cn.ConnectionString = "Data Source=.;uid=sa;pwd=wintellect;database=master"
            cn.Open()
            Dim sql As String = "Select * from student where rollno=" + comboBox1.SelectedItem
            Dim cmd As New SqlCommand(sql, cn)
            Dim dr As SqlDataReader = cmd.ExecuteReader()
            If dr.HasRows Then
                        dr.Read()
                        Dim data As Byte() = DirectCast(dr("MemPhoto"), Byte())
                        Dim ms As New MemoryStream(data)
                        pictureBox1.Image = Image.FromStream(ms)
            End If
            cn.Close()



U have modify connection string and select query based on ur requirements
-----------------------------------------------------------------------

VB
Dim cmd As New SqlCommand("Select MemPhoto from FamilyDetails where FamilyID=@FamilyID", sqlcon)
       cmd.Parameters.Add("@FamilyID", SqlDbType.Int).Value = txtsearchbox.Text
       Dim dt As New DataTable
       Dim adp As New SqlDataAdapter(cmd)
       adp.Fill(dt)


       If dt.Rows(0)("").ToString IsNot Nothing Then 'See Rows(0)
           Dim data1 As Byte() = DirectCast(dt.Rows(0)(""), Byte())
           Dim ms As New MemoryStream(data1)
           PictureBox1.Image = Image.FromStream(ms)
           ms.Close()
       End If

       If dt.Rows(1)("").ToString IsNot Nothing Then 'See Rows(1)
           Dim data2 As Byte() = DirectCast(dt.Rows(0)(""), Byte())
           Dim ms As New MemoryStream(data2)
           PictureBox2.Image = Image.FromStream(ms)
           ms.Close()
       End If
       If dt.Rows(2)("").ToString IsNot Nothing Then 'See Rows(2)
           Dim data3 As Byte() = DirectCast(dt.Rows(0)(""), Byte())
           Dim ms As New MemoryStream(data3)
           PictureBox3.Image = Image.FromStream(ms)
           ms.Close()
       End If
       ................................................upto seven picturebox


In above code like hard coded,i mean, we know 7 photo and 7 picturebox in form,so without looping i will bind photo in each picturebox using dt.Rows(0)("") to PictureBox1,dt.Rows(1)("") to PictureBox2 and so on.so at lest u change this part by looping .
 
Share this answer
 
v7
Comments
Member 10279246 29-Jul-15 5:40am    
Yes my all images are saved in binary format in sql.... so what I have to do now
Aravindba 29-Jul-15 5:45am    
check this link
http://www.codeproject.com/Articles/437937/Save-and-Retrieve-Image-from-a-SQL-Server-Database
u can download and pass file path to picture box or directly pass file stream to picture box
PictureBox1.BackgroundImage = Image.FromStream(ms, True)
Member 10279246 29-Jul-15 7:21am    
but it is displaying only one photo... I have seven member... how can I show one by one....
Aravindba 29-Jul-15 21:21pm    
You have 7 picturebox ? and u store 7 photo in different row or different column ?
if yes means,how u show currently one photo like that u show all photo in all picture box,Use For Each and bind photo in 7 picturesbox
Member 10279246 30-Jul-15 1:16am    
I have one table with 7 rows.. and each row has one image. So I have 7 photos in seven records.. I want to show all 7 record's photo to seven different photoboxes on my form..
If you give me code will be helpful.

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