从操作方法中将图像对象保存到SQL Server数据库中
- 论坛
- 从操作方法中将图像对象保存到SQL Server数据库中
10 浏览
从操作方法中将图像对象保存到SQL Server数据库中
[HttpPost] public void Test(HttpPostedFileBase file) { UsersContext db = new UsersContext(); byte[] image = new byte[file.ContentLength]; file.InputStream.Read(image, 0, image.Length); CrimeReport i = new CrimeReport { ImageId=1, ImageName="Ali", ImageContent = image, Active=true }; try { db.CrimeReports.Add(i); db.SaveChanges(); } catch (Exception e) { // Handle the exception } }
在db.CrimeReports.Add(i)出现了一个异常。