Thursday, December 17, 2009

Storing images in database (sqlserver) vb.net code

Here fup1 means file upload control

Dim intImageSize As Int64
Dim strImageType As String
Dim ImageStream As Stream

intImageSize = fup1.PostedFile.ContentLength
strImageType = fup1.PostedFile.ContentType
ImageStream = fup1.PostedFile.InputStream
Dim ImageContent(intImageSize) As Byte
Dim intStatus As Integer
intStatus = ImageStream.Read(ImageContent, 0, intImageSize)
Dim myCommand As New SqlCommand("update staff_details set photo= @imgsamgetimage where staffid='" & Emp(2) & "'", Conn)
myCommand.Parameters.Add("@imgsamgetimage", SqlDbType.Image, ImageContent.Length).Value = ImageContent
myCommand.ExecuteNonQuery()
Conn.Close()

No comments:

Post a Comment