0

I am looking to insert both image and audio into sql with this code , how can I make this binary reader to read multiple files ? audio and image ?

protected void Button1_Click1(object sender, EventArgs e)
    {

        using (BinaryReader br = new BinaryReader(FileUpload1.PostedFile.InputStream))
        {
            byte[] bytes = br.ReadBytes((int)FileUpload1.PostedFile.InputStream.Length);
            string strConnString = ConfigurationManager.ConnectionStrings["CMSConnectionString"].ConnectionString;
            using (SqlConnection con = new SqlConnection(strConnString))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.CommandText = "INSERT INTO tblComplaint(customerName, type, status,reply,Date,image) VALUES (@customerName, @type, @status,@reply,@Date,@audio)";
                    cmd.Parameters.AddWithValue("@customerName", TextBox1.Text);
                    cmd.Parameters.AddWithValue("@type", TextBox2.Text);
                    cmd.Parameters.AddWithValue("@status", TextBox3.Text);
                    cmd.Parameters.AddWithValue("@reply", TextBox4.Text);
                    cmd.Parameters.AddWithValue("@date", TextBox5.Text);
                    cmd.Parameters.AddWithValue("@audio", bytes);
                    cmd.Connection = con;
                    con.Open();
                    cmd.ExecuteNonQuery();
                    con.Close();
                }
            }
        }
        Response.Redirect(Request.Url.AbsoluteUri);
शेखर
  • 17,412
  • 13
  • 61
  • 117
Asfand
  • 1
  • 2
  • Allow multiple files, stream the image and the audio from the posted files collection into two byte arrays, use your existing code. I personally wouldn't store images in a database; I'd put them in a filesystem because that's what filesystems are for; files. I'd put the path to the file in the db – Caius Jard Mar 27 '21 at 05:24
  • I used this code but still image is not being uploaded. using (BinaryReader br = new BinaryReader(FileUpload1.PostedFile.InputStream)) { byte[] bytes = br.ReadBytes((int)FileUpload1.PostedFile.InputStream.Length); byte[] bytes1 = br.ReadBytes((int)FileUpload2.PostedFile.InputStream.Length); string strConnString = ConfigurationManager.ConnectionStrings["CMSConnectionString"].ConnectionString; – Asfand Mar 27 '21 at 23:41
  • Please don't put code in comments. Edit your question – Caius Jard Mar 28 '21 at 04:57

0 Answers0