Adding multiple pictures from a form to SQL Database in VB.net

Topzturvins07 1 Tallied Votes 342 Views Share

I used this code to store convert pictures to "binary" inoreder to save in database but it stores only one picture from two pictureboxes.


let someone show me how, you can convert pictuers in two seperate 'picturebox ("picturebox1 and Picturebox2")' using the function in the code snippet on something similar.
and also using the "if" condition to validate checks

deleodesanmi commented: doing a great job for budding programmers +0
Public Function GetByteArrayFromImage2() As Byte()
        Dim piccollect As New PictureBox
        

        Dim ms As New System.IO.MemoryStream
        With PictureBox2
            .Image.Save(ms, PictureBox2.Image.RawFormat)


        End With


        Dim outBytes(CInt(ms.Length - 1)) As Byte
        ms.Seek(0, System.IO.SeekOrigin.Begin)
        ms.Read(outBytes, 0, CInt(ms.Length))
        Return outBytes
        GetByteArrayFromImage2 = ms.GetBuffer
        ms.Close()
    End Function
raymyster -13 Light Poster

very interesting!

kplcjl 17 Junior Poster

http://www.daniweb.com/forum58.html


1. You declare piccollect, assign it memory and then never use it.
2. You ask how to handle multiple picture boxes. Don't hardcode the picture box!!!!

Public Function GetByteArrayFromImage2(ByRef pb as PictureBox ) As Byte() Dim ms As New System.IO.MemoryStream With pb .Image.Save(ms, pb.Image.RawFormat) End With [\code] ...

[code=vb] Dim a(0) as Byte Dim b(0) as Byte a = GetByteArrayFromImage2(picturebox1) b = GetByteArrayFromImage2(Picturebox2) [\code] 3. "Return outBytes" terminates your logic, the last two statements are never executed. The only way they would execute is if the above statement was in an If statement and the false path is followed.[code=vb]
Public Function GetByteArrayFromImage2(ByRef pb as PictureBox ) As Byte()
Dim ms As New System.IO.MemoryStream
With pb
.Image.Save(ms, pb.Image.RawFormat)
End With
[\code]
...

Dim a(0) as Byte Dim b(0) as Byte a = GetByteArrayFromImage2(picturebox1) b = GetByteArrayFromImage2(Picturebox2) [\code] 3. "Return outBytes" terminates your logic, the last two statements are never executed. The only way they would execute is if the above statement was in an If statement and the false path is followed.[code=vb]
Dim a(0) as Byte
Dim b(0) as Byte
a = GetByteArrayFromImage2(picturebox1)
b = GetByteArrayFromImage2(Picturebox2)
[\code]
3. "Return outBytes" terminates your logic, the last two statements are never executed. The only way they would execute is if the above statement was in an If statement and the false path is followed.

kplcjl 17 Junior Poster

Sorry, I replied to the code snippet instead of your question. Read above to see my comments.

deleodesanmi 0 Newbie Poster

pls give the code that adds content of a single(not two) picture box and syntax that stores the image to a field in the table
also the code that displays the field from databsee to a form

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.