Insert image type column to SQlServer
The below is the related code ,but pls remember to clear the image column in updateCommand 's syntax,and updateparams in aspx file.
If you don't clear it , the sqlcommand will reexecute it. and it'll produce a error.
Public Sub UpdatePhoto(ByVal Id As Integer, ByVal PhotoFile As FileUpload)
If (PhotoFile Is Nothing) Or (Not PhotoFile.HasFile) Then
Return
End If
Using cn As New SqlConnection(GlobalVarible.ConnectionString)
Using cmd As New SqlCommand("update StaffDemo set Image=@Image where id=@ID", cn)
cmd.Parameters.Add("ID", Data.SqlDbType.Int).Value = Id
cmd.Parameters.Add("@Image", Data.SqlDbType.Image).Value = PhotoFile.FileBytes
cn.Open()
cmd.ExecuteNonQuery()
End Using
End Using
End Sub