title: Uploading an image and save to SQL database in visual web developer
body: <p>I have made a store procedure in database for adding an image, but now the problem is, I need to get the image data on client side and convert into bytes to insert to database, Here is my code i'm using:</p>
  
  <pre><code>     public static void AddImg (string asImgName, string asFilePath, string asUser, string asRemarks)
      {
          cmd = new SqlCommand("sp_InsertImage", SqlConnect.con);
          cmd.CommandType = CommandType.StoredProcedure;
          cmd.Parameters.Add("@Image_Name", SqlDbType.NVarChar).Value = asImgName;
          cmd.Parameters.Add("@Image", SqlDbType.VarBinary).Value = File.ReadAllBytes(asFilePath);
          cmd.Parameters.Add("@Uploader", SqlDbType.NVarChar).Value = asUser;
          cmd.Parameters.Add("@Remarks", SqlDbType.NVarChar).Value = asRemarks;
          cmd.Parameters.Add("@UploadDate", SqlDbType.DateTime).Value = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
          cmd.ExecuteNonQuery();
      }
  </code></pre>
  
  <p>Now I'm facing a problem:
  On line 5 of the code 
  <code>"cmd.Parameters.Add("@Image", SqlDbType.VarBinary).Value = File.ReadAllBytes(asFilePath);"</code>
  It only reads the server side path, so what changes do I need to make so that I can upload the image?</p>
  
  <p>Thanks</p>
  
  <p>======================================
  I solved this problem by using the upload file control in VWD</p>
  
  <pre><code>fileUpload1.FileBytes
  </code></pre>