This is the code I use to add the values into the database:
SqlConnection con = new SqlConnection(@"Data Source=WIN-39OFKTSHQUA;Persist Security Info=True;User ID=sa;Password=asd123");
con.Open();
int id = Convert.ToInt16(textBox1.Text);
string name = textBox2.Text;
string fname = textBox3.Text;
string conc = textBox4.Text;
string mail = textBox5.Text;
string add = textBox6.Text;
int age = Convert.ToInt32 (textBox7.Text);
MemoryStream stream = new MemoryStream();
pictureBox1.Image.Save(stream, ImageFormat.Jpeg);
Byte[] imageArray = stream.ToArray();
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "insert into Student values ('" + id + "','" + name + "','"+age+"','" + fname + "','" + conc + "','" + mail + "','" + add + "','"+imageArray+"')";
cmd.ExecuteNonQuery();
Now, I want to retrieve the image on another form into a picturebox. I have applied all the solutions that are available on the internet but I am unable to retrieve the image and nothing is working, every time I get an error and most of the times the error is "Parameter is not valid".
For now, I am retrieving data of the selected ids from combobox except for image, please help me.
I tried many solutions some of the recent ones are following
Loading PictureBox Image From Database
https://www.codeproject.com/Tips/465950/Why-do-I-get-a-Parameter-is-not-valid-exception-wh
byte[]array to a string will yield something like "System.Byte[]". You should anyhow use a parametrized statement instead of building an SQL statement by string concatenation.ImageType is deprecated. As mentioned, useVARBINARY(MAX)-- The code you presented here, sorry to say it, is wrong in all departments (and cannot work, see my first comment). Also, you REALLY need to use Parameters, don't concatenate strings to build a Query, it's very important