in my following code i want to return data the null if my PictureBox(pbspic) is null else if PictureBox(pbspic) contains a picture I want data to return picture byte so that I can save null or picture in my database
using (MemoryStream stream = new MemoryStream())
{
Bitmap bmp = new Bitmap(pbspic.Image);
bmp.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
stream.Position = 0;
byte[] data = new byte[stream.Length];
stream.Read(data, 0, data.Length);
return data;
}
cmd.Parameters.Add("@Photo", SqlDbType.VarChar).Value = data;
dm2.ExecActQuery("StudentsInsert", cmd);
try creating a metthod of your stream and then call it for picture like this
USAGE: