1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| Private Sub BtnAddImage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnAddImage.Click
Dim l_strFileNamePath As String
Dim MyselectCommandInsertImages As New OdbcCommand
Dim oStream As New System.IO.MemoryStream
Dim l_strRequeteInsertImage As String = "INSERT INTO images (id_image,image) VALUES ('3', @Image)"
ChargerImage.Filter = "Fichiers JPG(*.jpg)|*.jpg"
ChargerImage.ShowDialog()
l_strFileNamePath = ChargerImage.FileName
Dim img As New Bitmap(l_strFileNamePath)
img.Save(oStream, System.Drawing.Imaging.ImageFormat.Jpeg)
Dim bytImage As Byte() = oStream.GetBuffer
With MyselectCommandInsertImages
.CommandType = CommandType.Text
.Connection = MyConnexion
.CommandText = l_strRequeteInsertImage
.Parameters.Add("@Image", Data.Odbc.OdbcType.Image).Value = bytImage
MyselectCommandInsertImages.ExecuteNonQuery()
End With
End Sub |
Partager