Whenever i try to save picture from picturebox to access database i usually get this error message "An unhandled exception of type 'System.ArgumentNullException' occurred in mscorlib.dll
Additional information: Path cannot be null."
This is my code for saving to database
private void cmdSave_Click(object sender, EventArgs e)
{
int rowCount;
rowCount = num.Next();
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = DBConnection;
FileStream stream = null;
StreamReader reader = null;
stream = new FileStream(picPreview.ImageLocation, FileMode.Open, FileAccess.Read, FileShare.Read);
reader = new StreamReader(stream);
byte[] fbyteArray = new byte[stream.Length];
stream.Read(fbyteArray, 0, Convert.ToInt32(stream.Length));
if(cboCoordinateLabel.Text=="Artery")
{
cmd.CommandText = "INSERT INTO artery VALUES(@image_id,@coordinate,@image)";
cmd.Parameters.Add("@image_id", OleDbType.Integer).Value = rowCount;
cmd.Parameters.Add("@coordinate", OleDbType.VarChar).Value = coordinate;
cmd.Parameters.Add("@image", OleDbType.Binary, Convert.ToInt32(stream.Length)).Value = fbyteArray;
DBConnection.Open();
}
else if(cboCoordinateLabel.Text=="Vein")
{
cmd.CommandText = "INSERT INTO veins VALUES(@id,coordinate,@image)";
cmd.Parameters.Add("@image_id", OleDbType.Integer).Value = rowCount;
cmd.Parameters.Add("@coordinate", OleDbType.VarChar).Value = coordinate;
cmd.Parameters.Add("@image", OleDbType.Binary, Convert.ToInt32(stream.Length)).Value = fbyteArray;
DBConnection.Open();
}
else
{
MessageBox.Show("Please select an option from the coordinate label to proceed");
}
try
{
cmd.ExecuteNonQuery();
MessageBox.Show("Record has been saved");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
MessageBox.Show(ex.StackTrace.ToString());
}
finally
{
DBConnection.Close();
}
}