I´ve stream video on a pictureBox control, and I want to get image from PictureBox, to store on a table on SQL Server. PictureBox show stream but, PictureBox retrieve null.
What is wrong?
private void button1_Click(object sender, EventArgs e){
SqlConnection con = new SqlConnection("Data Source=IBM-PC\\SQLEXPRESS2;Initial Catalog=DBACCESS;Integrated Security=True");
if (cmrConductor.Image == null){
mensajeOK("Error");
}else{
MemoryStream ms = new MemoryStream();
cmrConductor.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
byte[] Pic_arr = new byte[ms.Length];
ms.Position = 0;
ms.Read(Pic_arr, 0, Pic_arr.Length);
SqlCommand cmd = new SqlCommand("INSERT INTO tblUsers (fldCode, fldPic) VALUES (@fldCode, @fldPic)", con);
cmd.Parameters.AddWithValue("@fldCode", txtId.Text);
cmd.Parameters.AddWithValue("@fldPic", Pic_arr);
con.Open();
try{
int res = cmd.ExecuteNonQuery();
if (res > 0){
MessageBox.Show("insert");
}
}
catch (Exception ex){
MessageBox.Show(ex.Message);
}
finally{
con.Close();
}
}
}