更新Linq查询图像(文件上载)

时间:2015-07-07 14:58:41

标签: c# asp.net linq

如何设置真正的查询更新?我无法得到这部分

 var image = add.Image.ToArray(); 

我必须从UserImage

获取图片列
            string fileName = FileUpload1.FileName;

            byte[] fileByte = FileUpload1.FileBytes;
            Binary binaryObj = new Binary(fileByte);

            var add = from u in db.UserImage
                          where u.User_Id == id
                          select u;

            foreach (var u in update7)
            {
                u.Image = binaryObj;
                u.ImageObj = fileName;

            }   


            db.SubmitChanges();

            var image =*add.Image*.ToArray();
            byte[] foto = (byte[])image;
            TypeConverter cc = TypeDescriptor.GetConverter(typeof(Bitmap));
            Bitmap my = (Bitmap)cc.ConvertFrom(foto);

            string img = Convert.ToBase64String(foto);
            Image1.ImageUrl = string.Format("data:image/Bmp;base64,{0}", img);

2 个答案:

答案 0 :(得分:0)

你可以试试这个吗?我的2美分。

var add = from u in db.UserImage
          where u.User_Id == id
          select u;
foreach (var u in add)
{
   u.Image = binaryObj;
   u.ImageObj = fileName;
}
db.SaveChanges();

答案 1 :(得分:0)

我解决了

            var add = (from u in db.UserImage
                       where u.User_Id == id
                       select u).ToList();

            foreach (var u in add)
            {
                u.Image = binaryObj;
                u.ImageObj = fileName;

            }



            db.SubmitChanges();

            var image = add[0].Image.ToArray();