Click here to Skip to main content
15,868,085 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Everyone,

I am developing 1 desktop application to my friend office,in that application i can store multiple images and i can retrieve the information for the same..My issue here is after retrieving the information when i click on update button I'm getting runtime exception i.e (Empty path is not legal exception)..

Here is the code which I wrote under updatebutton method:

C#
public partial class CustomerDetails : Form
    {

        string imageloc = "";
        string imageloc1 = "";
        string imageloc2 = "";
        string imageloc3 = "";
        string imageloc4= " ";
   public static Byte[] Imagesave(string imagelocation)
        {
            byte[] img = null;
           /*Empty path is not legal error*/ FileStream fs = new FileStream(imagelocation, FileMode.Open, FileAccess.Read);
            BinaryReader br = new BinaryReader(fs);
            img = br.ReadBytes((int)fs.Length);
            fs.Close();
            br.Close();
            return img;
        }
private void btnupdateinfo_Click(object sender, EventArgs e)
        {

            string scn = ConfigurationManager.ConnectionStrings["Myconn"].ConnectionString;
            using (SqlConnection cn = new SqlConnection(scn))
            {
                using (SqlCommand cmd = new SqlCommand("SP_UpdateInfo", cn))
                {
                    try
                    {


                        cmd.CommandType = CommandType.StoredProcedure;

                        cmd.Parameters.AddWithValue("@Hp_Number", tbhpnum.Text);
                        cmd.Parameters.AddWithValue("@Customer_Name", tbcusnam.Text);
                        cmd.Parameters.AddWithValue("@Customer_Contact_Number", tbcusmblno.Text);
                        cmd.Parameters.AddWithValue("@Guarantor_Name", tbguanam.Text);
                        cmd.Parameters.AddWithValue("@Guarantor_Contact_Number", tbguamblno.Text);
                        cmd.Parameters.AddWithValue("@Hp_Date", DateTime.Parse(tbhpdat.Text));
                        cmd.Parameters.AddWithValue("@Customer_Address", tbcusadd.Text);
                        cmd.Parameters.AddWithValue("@Vehicle", tbveh.SelectedItem.ToString());
                        cmd.Parameters.AddWithValue("@Vehicle_Model", tbvehmod.SelectedItem.ToString());
                        cmd.Parameters.AddWithValue("@Vehicle_Number", tbvehnum.Text);
                        cmd.Parameters.AddWithValue("@Chasis_Number", tbchanum.Text);
                        cmd.Parameters.AddWithValue("@Engine_Number", tbengnum.Text);
                        cmd.Parameters.AddWithValue("@FC_Date", DateTime.Parse(tbfcdat.Text));
                        cmd.Parameters.AddWithValue("@Insurance_Date", DateTime.Parse(tbinsdat.Text));
                        cmd.Parameters.AddWithValue("@Insurance_Amount",                               Convert.ToInt32(tbinsamt.Text));
                        cmd.Parameters.AddWithValue("@Paid_Amount", Convert.ToInt32(tbpaiamt.Text));
                        cmd.Parameters.AddWithValue("@Paid_Date", DateTime.Parse(tbpaidat.Text));
                        cmd.Parameters.AddWithValue("@Vehicle_Pic",Imagesave(imageloc));
                        cmd.Parameters.AddWithValue("@Customer_Pic", Imagesave(imageloc1));
                        cmd.Parameters.AddWithValue("@Guarantor_Pic", Imagesave(imageloc2));
                        cmd.Parameters.AddWithValue("@Documents_Pic", Imagesave(imageloc3));
                        cmd.Parameters.AddWithValue("@Insurance_Pic", Imagesave(imageloc4));

                        if (cn.State != ConnectionState.Open)
                            cn.Open();

                        int count = cmd.ExecuteNonQuery();
                        if (count == 1)
                        {
                            MessageBox.Show(count.ToString() + "Customer(s) Record(s) has Updated                     Successfully .", "Succes", MessageBoxButtons.OK);
                        }


                    }

                    catch (SqlException ex)
                    {
                        MessageBox.Show(ex.ToString());

                    }
                    finally
                    {
                        if (cn.State == ConnectionState.Open)
                            cn.Close();
                    }
                }
            }

        }
Posted

Hi,

As per the exception, the exception is accrued because any of your variable imageloc is empty that why.
you need to validation first all your local variable.
imageloc, imageloc1...imageloc4 then convert into Image bytes.

Thanks and Regards,
Maruf
 
Share this answer
 
Hi,

After retrieving information from the database,if i doesn't make any changes in pictureboxes that time only i'm getting this exception,but if i update all the existing pictures from the pictureboxes then i didn't get any exception...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900