Click here to Skip to main content
15,880,364 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello everyone :)

how i can save two image from two pictureBox into sql with one filestream command? i think i have to makearry but im not sure how so if you could please give hand
and this is my code i have repeated some line !

C#
private void button2_Click(object sender, EventArgs e)
        {
            byte[] bt = null;

      FileStream fs = new FileStream(pictureBox1.ImageLocation, FileMode.Open, FileAccess.Read);// this is for first image selected in picbox1
            FileStream fs2 = new FileStream(pictureBox2.ImageLocation, FileMode.Open, FileAccess.Read);// here i repeated the upper line 
            
            BinaryReader bnr = new BinaryReader(fs);
            BinaryReader bnr1 = new BinaryReader(fs2);//here
            bt = bnr1.ReadBytes((int)fs2.Length);// again 
            bt = bnr.ReadBytes((int)fs.Length);

 SqlCommand cmd = new SqlCommand("insert into tbldesgin(dsname,fside,bcside)values(@dsname,@fside,@bcside)", cn);
            cmd.Parameters.Add(new SqlParameter("@fside", bt));
            cmd.Parameters.Add(new SqlParameter("@bcside", bt));
            
            cmd.Parameters.AddWithValue("@dsname", textBox1.Text);
            
            cn.Open();
            cmd.ExecuteNonQuery();
            cn.Close();
            MessageBox.Show("data has been sent");
            pictureBox1.Image = null;

        }
Posted

1 solution

Pretty simple, since you have the images. Ignore the location, and use the current data in the PictureBox.Image property.
See here: Why do I get a "Parameter is not valid." exception when I read an image from my database?[^] - it shows how to save an Image into SQL - all you have to do is "double up" the code, and insert two byte arrays instead of one.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900