title: How to Upload Selected Multiple Images into the Database
body: <p>I need to Upload Image selected in the Website into the DB My project has multiple File Select "File Upload" how can I Upload those multiple Files into Database the Image data in Binary Format, My Code is           </p>
  
  <pre><code>    protected void Button1_Click(object sender, EventArgs e)
  
     {
  
          string Qry = "insert into tblFiles values(@data)";
          SqlConnection con = new SqlConnection(@"Data Source=ESLHPC17\SQL2008;Initial Catalog=dbFiles;User ID=user;Password=password");
  
          SqlCommand cmd = new SqlCommand(Qry,con);
          cmd.Parameters.Add("@data") = FileUpload1.FileBytes;
  
      }
  </code></pre>
  
  <p>I am using the Following Web Handler to Save the Files in local Folder </p>
  
  <pre><code>&lt;%@ WebHandler Language="C#" Class="Upload" %&gt;
  
  using System;
  using System.Web;
  using System.IO;
  
  
  public class Upload : IHttpHandler {
  
  public void ProcessRequest (HttpContext context) {
      context.Response.ContentType = "text/plain";
      context.Response.Expires = -1;
      try
      {
          HttpPostedFile postedFile = context.Request.Files["Filedata"];
  
          string savepath = "";
          string tempPath = "";
          tempPath = System.Configuration.ConfigurationManager.AppSettings["FolderPath"]; 
          savepath = context.Server.MapPath(tempPath);
          string filename = postedFile.FileName;
          if (!Directory.Exists(savepath))
              Directory.CreateDirectory(savepath);
  
          postedFile.SaveAs(savepath + @"\" + filename);
          context.Response.Write(tempPath + "/" + filename);
          context.Response.StatusCode = 200;
      }
      catch (Exception ex)
      {
          context.Response.Write("Error: " + ex.Message);
      }
  }
  
  public bool IsReusable {
      get {
          return false;
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>and I use the below Script</p>
  
  <pre><code> &lt;script type = "text/javascript"&gt;
        $(window).load(
  function () {
      $("#&lt;%=FileUpload1.ClientID%&gt;").fileUpload({
          'uploader': 'scripts/uploader.swf',
          'cancelImg': 'images/cancel.png',
          'buttonText': 'Browse Files',
          'script': 'Upload.ashx',
          'folder': 'Uploads',
          'fileDesc': 'Image Files',
          'fileExt': '*.jpg;*.jpeg;*.gif;*.png',
          'multi': true,
          'auto': false
      });
  </code></pre>
  
  <p>but I want to store the Images in Database</p>
  
  <hr>
  
  <p>@ Damith </p>
  
  <p>I have tried in with the below mentioned code but it didn't worked,</p>
  
  <pre><code>   protected void Button1_Click(object sender, EventArgs e)
      {
          string FolderPath=@"E:\Rajesh_Kumar\Application\Valuation\ExamManagement\ExamManagement\Uploads";
          string path = System.Configuration.ConfigurationManager.AppSettings[FolderPath];
          string Qry = "insert into tblFiles values(@data) Values (data)";
          SqlConnection con = new SqlConnection(@"Data Source=ESLHPC17\SQL2008;Initial Catalog=dbFiles;User ID=rajesh";
          StreamReader sr = new StreamReader(path);
          while (sr.ReadLine() != null)
          {
  
                  using (SqlCommand cmd = new SqlCommand(Qry, con))
                  {
                      cmd.Parameters.Add("@data",SqlDbType.VarBinary).Value = path;
                      con.Open();
                      cmd.ExecuteNonQuery();
                  }
              con.Close();
              con.Dispose();
          }
  
      }
  </code></pre>