5
Answers

Empty path is not legal exception while updating images in

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:

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(); 
} } } }


Answers (5)