1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| Dim ms As New MemoryStream
Me.PictureBox1.Image.Save(ms, Me.PictureBox1.Image.RawFormat)
Dim arrayImage() As Byte = ms.GetBuffer
ms.Close() ' Closes the Memory Stream
Dim nStr As String = Me.Label1.Text.Substring(Me.Label1.Text.LastIndexOf("\") + 1)
Dim strQuery As String = "INSERT INTO Pic(Name, Picture) VALUES(@Name, @Picture)"
Dim objcommand As New SqlCommand(strQuery, con)
With objcommand
.Parameters.Add(New SqlParameter("@Name", SqlDbType.NVarChar, 50)).Value = nStr
.Parameters.Add(New SqlParameter("@Picture", SqlDbType.Image)).Value = arrayImage
End With
con.Open()
objcommand.ExecuteNonQuery()
MessageBox.Show("Image Saved Into the DataBase")
con.Close() |
Partager