hey all,
im sort of new on .net and i was hoping if u can help me again. i am to search a a student record on sql server 2005 database. my problem is, i can search for records but i failed to display their pictures in the picturebox.

here is my code for searching:

str = "select * from studinfo_t where Studno like ('" & Trim(txtSearch.Text) & "%')"

            Try
                con.Open()
                Dim com1 As New SqlClient.SqlCommand(str, con)
                Dim dr As SqlClient.SqlDataReader = com1.ExecuteReader

                While dr.Read
                    txtStudNum.Text = "" & (dr.GetValue(0))
                    txtLName.Text = "" & (dr.GetValue(1))
                    txtFirst.Text = "" & (dr.GetValue(2))
                    txtMI.Text = "" & (dr.GetValue(3))
                    txtGender.Text = "" & (dr.GetValue(4))
                    dpBirthday.Text = "" & (dr.GetValue(5))
                    txtAddress.Text = "" & (dr.GetValue(6))
                    cbCourse.Text = "" & (dr.GetValue(7))
                    txtSection.Text = ""(dr.GetValue(8))           
                    picStudImg.Image = Image.FromStream(New MemoryStream(CType(dr.GetValue(9), Byte())))
                End While
                If Not dr.HasRows Then
                    MsgBox("No records found. Please try again.", MessageBoxIcon.Error, "No records found")
                    txtSearch.Clear()
                End If
                con.Close()
            Catch ex As Exception
                con.Close()
            End Try

i was able to display all except for the image. i dont have any error on this code so i dont know what went wrong and why is it that the pic is not showing.. thanks in advance

I think i am using a easy and bad idea ...
First i will load the image path that saved in student's form to a text box or variable then i will change the image of the picture box with that image id ....

hey Vineeth K, tnx for the post. if i am to follow ur suggestion, then i am to start my code allover again ryt? because i am converting images into bytes and stoe into the database. do u think im doing it right if i am to change it?

Keeping pictures in a database is not a good idea. It is much better to store the path to the picture file and use that to load your pictures.

Pictures can make your database grow very large very fast. As an example, every time you update a record, even though your not changing the actual picture, a whole new copy of the record is made in the database (until you you do database maintainance).

Hi,
Pls am new on vb.net and sql server. Pls can you send me the sample code to convert a picture in byte and store in the database. I mean the in conversion code, insert statement and the select statement to retrieve the picture.
Thanks.
Dapsin

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.