Hello Dears,
I was Maked Pictures table in sql server 2005 with Two Col pic_Id (int) and picture(binary)
i need now ro insert image into this table by Asp.net under VB.net Code i have in my form FileUpload and button control
and this is my Code
ProtectedSub btnLoad_Click(ByVal senderAsObject,ByVal eAs System.EventArgs)Handles btnLoad.ClickDim content()AsByte = ReadBitmap2ByteArray(FileUpload1.PostedFile.ContentType)
StoreBlob2DataBase(content)
EndSub
Function ReadBitmap2ByteArray(ByVal FileNameAsString)AsByte()Dim imageAs Drawing.Bitmap =New Drawing.Bitmap(FileName)
Dim streamAs IO.MemoryStream =New IO.MemoryStream()image.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp)
Return stream.ToArrayEndFunction
Sub StoreBlob2DataBase(ByVal contentAsByte())
con.Open()
Dim cmAsNew SqlCommand("Insert into Pictures(Pic_Id,picture) values(@.id,@.pic)", con)cm.Parameters.AddWithValue("@.ID", 1)
Dim p1AsNew SqlParameterp1.ParameterName ="@.pic"
p1.SqlDbType = Data.SqlDbType.Binary
p1.Value = content
p1.Size = content.Length
cm.Parameters.Add(p1)
cm.ExecuteNonQuery()
EndSub
when i make run to my website it give me an Exeption in this statement
Dim imageAs Drawing.Bitmap =New Drawing.Bitmap(FileName)
it tell me that Parameter is not valid
i need help about this please
with my Best regard
khalil
In this line:
Dim content()AsByte = ReadBitmap2ByteArray(FileUpload1.PostedFile.ContentType)
You are passing in the contentType rather than a filename.
|||HI
its does not work also its give me the same error what can i do
|||Of course it gives you the same error, I didn't fix it, I just pointed out what was wrong. Pass in the filename of the file, not the contenttype.
No comments:
Post a Comment