I use Entity Framework and LINQ.
Simply, I want to take image file from fileupload control, and save it in a SQL Server database. But I get an error..
Table: Images
imageId int
imageData varbinary(max)
Stored procedure:
ALTER proc [dbo].[UploadImage]
(
@img varbinary(max)
)
as
insert into Images(imageData)
values(@img)
C# code (after choosing file and clicking the button):
while (FileUpload1.HasFile)
{
System.Drawing.Image img = System.Drawing.Image.FromStream(FileUpload1.PostedFile.InputStream);
byte[] imgByteArray = new byte[FileUpload1.PostedFile.InputStream.Length];
FileUpload1.PostedFile.InputStream.Read(imgByteArray, 0, (int)FileUpload1.PostedFile.InputStream.Length);
using (DummyDBEntities context=new DummyDBEntities())
{
context.UploadImage2(imgByteArray);
}
}
Can you help me figuring out the problem?
Thank you