954,515 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?

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

By Topzturvins07 on Sep 7th, 2009 4:07 pm

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

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

very interesting!

raymyster
Light Poster
27 posts since Jan 2008
Reputation Points: -3
Solved Threads: 0
 

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!!!!
[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]
...

[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
Junior Poster
149 posts since Sep 2009
Reputation Points: 16
Solved Threads: 12
 

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

kplcjl
Junior Poster
149 posts since Sep 2009
Reputation Points: 16
Solved Threads: 12
 

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

deleodesanmi
Newbie Poster
1 post since Feb 2010
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: