- Public Const MAX_IMAGE_SIZE As Long = 32768 ' 32 Ko
-
- ' ----------------------------------------------------------------------------------------
- ' Ajout d'un enregistrement
- ' ----------------------------------------------------------------------------------------
-
- Dim myCmd As SqlCommand
- Dim ms As New System.IO.MemoryStream
- Dim arrPicture() As Byte
-
- myCmd = New SqlCommand("insert into matable values (@id, @nom, @image)", myConnection)
- if not isnothnig(picture)
- picture.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)
- If ms.Length > MAX_IMAGE_SIZE Then
- ' Image trop grosse
- end if
- arrPicture = ms.GetBuffer()
- myCmd.Parameters.Add("@image", SqlDbType.Image).Value = arrPicture
- Else
- myCmd.Parameters.Add("@image", SqlDbType.Image).Value = DBNull.Value
- End If
- myCmd.Parameters.Add("@id", SqlDbType.Int).Value = 0
- myCmd.Parameters.Add("@nom", SqlDbType.Char).Value = "image1"
- myCmd.ExecuteNonQuery()
-
- ' ----------------------------------------------------------------------------------------
- ' Lecture d'un enregistrement
- ' ----------------------------------------------------------------------------------------
-
- Dim myCmd As SqlCommand
- Dim reader As SqlDataReader
- Public picture As Image
-
- myCmd = New SqlCommand("select * from matable", myConnection)
- reader = myCmd.ExecuteReader()
- while reader.read
- ' Traitement des autres champs ... puis :
- If Not reader.IsDBNull(2) Then
- Dim arrPicture(MAX_IMAGE_SIZE) As Byte
- reader.GetBytes(2, 0, arrPicture, 0, MAX_IMAGE_SIZE)
- Dim ms As New System.IO.MemoryStream(arrPicture)
- picture = [Image].FromStream(ms)
- ' Ici on peu appliquer n'importe quel traitement à l'objet picture
- ' comme par exemple le stocker dans un tableau ou l'afficher
- ' dans un picturebox etc ...
- End If
- end while
Public Const MAX_IMAGE_SIZE As Long = 32768 ' 32 Ko
' ----------------------------------------------------------------------------------------
' Ajout d'un enregistrement
' ----------------------------------------------------------------------------------------
Dim myCmd As SqlCommand
Dim ms As New System.IO.MemoryStream
Dim arrPicture() As Byte
myCmd = New SqlCommand("insert into matable values (@id, @nom, @image)", myConnection)
if not isnothnig(picture)
picture.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)
If ms.Length > MAX_IMAGE_SIZE Then
' Image trop grosse
end if
arrPicture = ms.GetBuffer()
myCmd.Parameters.Add("@image", SqlDbType.Image).Value = arrPicture
Else
myCmd.Parameters.Add("@image", SqlDbType.Image).Value = DBNull.Value
End If
myCmd.Parameters.Add("@id", SqlDbType.Int).Value = 0
myCmd.Parameters.Add("@nom", SqlDbType.Char).Value = "image1"
myCmd.ExecuteNonQuery()
' ----------------------------------------------------------------------------------------
' Lecture d'un enregistrement
' ----------------------------------------------------------------------------------------
Dim myCmd As SqlCommand
Dim reader As SqlDataReader
Public picture As Image
myCmd = New SqlCommand("select * from matable", myConnection)
reader = myCmd.ExecuteReader()
while reader.read
' Traitement des autres champs ... puis :
If Not reader.IsDBNull(2) Then
Dim arrPicture(MAX_IMAGE_SIZE) As Byte
reader.GetBytes(2, 0, arrPicture, 0, MAX_IMAGE_SIZE)
Dim ms As New System.IO.MemoryStream(arrPicture)
picture = [Image].FromStream(ms)
' Ici on peu appliquer n'importe quel traitement à l'objet picture
' comme par exemple le stocker dans un tableau ou l'afficher
' dans un picturebox etc ...
End If
end while