如何插入&;使用linq获取图像

如何插入&;使用linq获取图像,linq,Linq,首先 id (int) name (varchar) picture (image) 第二 id (int) post (varchar) age (int) 我想在第一个表中添加一条记录 然后我想使用id组合这两个表 然后我想填充一个gridview,其中post是“manager” (特别是我想知道如何将图像插入数据库以及如何使用网格视图显示它们。)要将图像插入到表中,您可以单击“保存”按钮尝试类似的操作

首先

id      (int)             
name (varchar)          
picture (image)  
第二

id (int)      
post (varchar)    
age (int)
  • 我想在第一个表中添加一条记录
  • 然后我想使用id组合这两个表
  • 然后我想填充一个gridview,其中post是“manager”

  • (特别是我想知道如何将图像插入数据库以及如何使用网格视图显示它们。)

    要将图像插入到表中,您可以单击“保存”按钮尝试类似的操作

        string fileName = FileUpload1.FileName;
        byte[] fileByte = FileUpload1.FileBytes;
        Binary binaryObj = new Binary(fileByte);
        DataClasses1DataContext context = new DataClasses1DataContext();
        //mem_images is the name of the table you dragged , use your table name here
        context.mem_images.InsertOnSubmit(new mem_image { mem_img=binaryObj  });
        context.SubmitChanges();
        Response.Write("<script>alert('Image Has Been Saved Successfully'</script>);
    

    希望这对您有所帮助,如果您有进一步的问题,请回复

    您是否正在使用
    linq to entities
    ?您尝试了什么?我只是想将图像存储在sql数据库中,并将它们返回到网格视图。这是gideon的答案吗?互联网上有很多关于在数据库中存储图像的信息。回答您的问题需要编写一个几乎完整的应用程序。
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.IO;
    
    namespace CwizBankApp
    {
        /// <summary>
        /// Summary description for $codebehindclassname$
        /// </summary>
    
        public class ShowImage : IHttpHandler
        {
    
    
            public void ProcessRequest(HttpContext context)
            {
                //context.Response.ContentType = "text/plain";
               // context.Response.Write("Hello World");
                string id =context.Request.QueryString["Id"];
    
    
                context.Response.ContentType = "image/jpeg";
                Stream strm = ShowEmpImg(id);
                byte[] buffer = new byte[4096];
                int byteSeq = strm.Read(buffer, 0, 4096);
                while (byteSeq > 0)
                {
                    context.Response.OutputStream.Write(buffer, 0, byteSeq);
                    byteSeq = strm.Read(buffer, 0, 4096);
                }
            }
            public Stream ShowEmpImg(string id)
            {
    
    
                DataClasses1DataContext context1 = new DataClasses1DataContext();
                var r = (from a in context1.mem_images where a.image_id==id select a).First() ;
                return new MemoryStream(r.mem_img.ToArray());
            }
    
            public bool IsReusable
            {
                get
                {
                    return false;
                }
            }
        }
    }
    
    custImage1.ImageUrl = "~/ShowImage.ashx?Id="+textbox.text