I have one form which contains one file upload control. on page load i am loading all data from database into the respective textboxes of form.
I have one update button but on click my data is not updating. below is my code of update button
When i change image it gets updated but not other fields
protected void ChangeProfile_Click(object sender, EventArgs e)
{
if (FileUpload1.PostedFile != null)
{
HttpPostedFile attFile = FileUpload1.PostedFile;
int attachFileLength = attFile.ContentLength;
if (attachFileLength > 0)
{
strFileName = Path.GetFileName(FileUpload1.PostedFile.FileName);
FileUpload1.PostedFile.SaveAs(Server.MapPath("~/CompanyLogo/" + strFileName));
string filepath = Server.MapPath("~/CompanyLogo/" + strFileName);
string path = "~/CompanyLogo/" + strFileName;
SqlConnection con = new SqlConnection("Data Source=jayraj-pc\\sqlexpress;Initial Catalog=Internship;Integrated Security=True;Pooling=False");
con.Open();
string str = "UPDATE Companies set FirstName='" + firstname.Text + "', LastName='" + lastname.Text + "', EmailID='" + email.Text + "', CompanyName='" + companyname.Text + "',Designation='" + designation.Text + "', ContactNo='" + mobileno.Text + "', Country='" + countrylist.SelectedItem.Text + "',Address='" + address.Text + "', CompanyCategory='" + companysector.SelectedItem.Text + "',NoOfEmployees='" + DropDownList5.SelectedItem.Text + "', Website='" + website.Text + "',AboutCompany='" + aboutcompany.Text + "', UserName='" + cusername.Text + "', CompanyLogo='" + path + "' where CompanyID=" + Convert.ToInt16(Session["CompanyID"].ToString());
SqlCommand cmd = new SqlCommand(str, con);
cmd.ExecuteNonQuery();
con.Close();
}
else
{
Updateprofile();
}
}
}
protected void Updateprofile()
{
SqlConnection con1 = new SqlConnection("Data Source=jayraj-pc\\sqlexpress;Initial Catalog=Internship;Integrated Security=True;Pooling=False");
con1.Open();
string str1 = "UPDATE Companies set FirstName='" + firstname.Text + "', LastName='" + lastname.Text + "', EmailID='" + email.Text + "', CompanyName='" + companyname.Text + "',Designation='" + designation.Text + "', ContactNo='" + mobileno.Text + "', Country='" + countrylist.SelectedItem.Text + "',Address='" + address.Text + "', CompanyCategory='" + companysector.SelectedItem.Text + "',NoOfEmployees='" + DropDownList5.SelectedItem.Text + "', Website='" + website.Text + "',AboutCompany='" + aboutcompany.Text + "', UserName='" + cusername.Text + "' where CompanyID=" + Convert.ToInt16(Session["CompanyID"].ToString());
SqlCommand cmd1 = new SqlCommand(str1, con1);
cmd1.ExecuteNonQuery();
Response.Write("kccngj");
con1.Close();
}