Quantcast
Channel: VBForums - Database Development
Viewing all articles
Browse latest Browse all 2918

Saving PictureBoxes to Database

$
0
0
ok so I have multiple PictureBoxes and when I press the single button "save" I want all PictureBoxes to save at once. Below is the code I currently have, but Visual Basic keeps coming back with the error "check to see if the object is null before calling the method" on line 6 (end of first "end if" statement_.

I realise there's also an issue with the MessageBox statement and I could always take it out entirely. My Main concern is the null statement. I'm very new with Visual Basic and coding and feel I've got to be close on this.

PHP Code:

Private Sub ButtonSave_Click(sender As ObjectAs EventArgsHandles ButtonSave.Click
        
For Each pb As PictureBox In GroupBoxKiosk101Side1.Controls.OfType(Of PictureBox)()
            If 
pb.Image Is Nothing Then
                Call Me
.CreateDefaultImageinPB(pb)
                
MessageBox.Show("Not all images are uploaded"MessageBoxButtons.OKMessageBoxIcon.Warning)
            
End If
            
Using PictureBox As Image = New Bitmap(pb.Image)
                
Using Stream As New IO.MemoryStream
                    PictureBox
.Save(StreamImaging.ImageFormat.Jpeg)
                    
cmd.Parameters.Add("@image"SqlDbType.VarBinary).Value Stream.GetBuffer()
                
End Using
            End Using
        Next
        end sub

    
Private Sub CreateDefaultImageinPB(_PictureBox As PictureBox)
        
_PictureBox.Image = New Bitmap(_PictureBox.Width_PictureBox.Height)
        
Dim graphics As Graphics graphics.FromImage(_PictureBox.Image)
        
Dim brush As Brush = New SolidBrush(Color.White)

        
graphics.FillRectangle(brush, New System.Drawing.Rectangle(00_PictureBox.Width_PictureBox.Height))

    
End Sub 


Viewing all articles
Browse latest Browse all 2918

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>