Jyoti Jodha

Jyoti Jodha

  • NA
  • 1.7k
  • 408.5k

Object reference not set to an instance of an object

Oct 6 2017 12:35 AM
Object reference not set to an instance of an object in asp.net c#
 
protected void Button1_Click1(object sender, EventArgs e)
{
if (!FileUpload1.HasFile)
{
Label9.Visible = true;
Label9.Text = "Please Select Image File";
}
else
{
int length = FileUpload1.PostedFile.ContentLength;
byte[] pic = new byte[length];
FileUpload1.PostedFile.InputStream.Read(pic, 0, length);
try
{
connection();
SqlCommand com = new SqlCommand("insert into Post_Room (Property_Type,Location,Mobile,Email,Rent,Description,Images) values (@Property_Type,@Location,@Mobile,@Email,@Rent,@Description,@Images)", con);
com.Parameters.AddWithValue("@Property_Type", DropDownList.SelectedValue);
com.Parameters.AddWithValue("@Location", txtlction.Text);
com.Parameters.AddWithValue("@Mobile", Txtmob.Text);
com.Parameters.AddWithValue("@Email", Txtemail.Text);
com.Parameters.AddWithValue("@Rent", Txtrent.Text);
com.Parameters.AddWithValue("@Description", Txtdec.Text);
com.Parameters.AddWithValue("@Images", pic);
com.ExecuteNonQuery();
Label9.Visible = true;
Label9.Text = "Image Uploaded Sucessfully"; //after Sucessfully uploaded image
con.Close();
}
catch (Exception ex)
{
Label9.Visible = true;
Label9.Text = ex.Message;
}
}
}
 

Answers (2)