السلام عليكم
sql server 2005هذا كود اضافة صورة الى قاعدة البيانات من نوع
: كود الاضافة
' Save image to byte array.
Dim imagedata() As Byte = image.ToByteArray(New Atalasoft.Imaging.Codec.JpegEncoder(75))
' Create the SQL statement to add the image data.
myConnection = New SqlConnection(CONNECTION_STRING)
Dim myCommand As SqlCommand = New SqlCommand
("INSERT INTO Atalasoft_Image_Database (Caption, ImageData) VALUES ('" + txtCaption.Text + "', @Image)", myConnection)
Dim myParameter As SqlParameter = New SqlParameter("@Image", SqlDbType.Image, imagedata.Length)
myParameter.Value = imagedata
myCommand.Parameters.Add(myParameter)
' Open the connection and execture the statement.
myConnection.Open()
myCommand.ExecuteNonQuery()
myConnection.Close()
وهذا كود القراءة من القاعدة
الكود :
' Establish connection and SELECT statement.
myConnection = New SqlConnection(CONNECTION_STRING)
Dim myCommand As SqlCommand = New SqlCommand
("SELECT ImageData FROM Atalasoft_Image_Database WHERE Caption = '" + txtCaption.Text + "'", myConnection)
myConnection.Open()
' Get the image from the database.
Dim imagedata() As Byte = CType(myCommand.ExecuteScalar(), Byte())
If (Not imagedata Is Nothing) Then
Dim image As AtalaImage = AtalaImage.FromByteArray(imagedata)
Return image
Else
MessageBox.Show("Image does not exist in database.")
Return Nothing
End If
myConnection.Close()