hi
Am getting this error While inserting image into Database
when i upload the image in the picturebox everything is fine (No exception)
but when i not upload the image it gives as exception
i want that if the image is present it saves and if not the null value should insert.
// This is the code for upload image in picture box //
private void pictureBoxstudentdetails_Click(object sender, EventArgs e)
{
OpenFileDialog open = new OpenFileDialog();
//image filters;
open.Filter = "jpeg|*.jpg|bmp|*.bmp|all files|*.*";
if (open.ShowDialog() == DialogResult.OK)
{
try
{
imagepath = open.FileName;
string filename = Path.GetFileName(imagepath);
string ext = Path.GetExtension(filename);
string contenttype = String.Empty;
FileStream fstream = new FileStream(imagepath, FileMode.Create) ;
data = new byte[fstream.Length];
pictureBoxstudentdetails.SizeMode = PictureBoxSizeMode.CenterImage;
pictureBoxstudentdetails.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBoxstudentdetails.Refresh();
pictureBoxstudentdetails.ImageLocation = imagepath;
fstream.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
}
// here is the code for saving the image into db using procedure //
data = File.ReadAllBytes(imagepath); // in this line am getting the error //
cmd.Parameters.AddWithValue("@Student_Image", data);