Click here to Skip to main content
15,913,587 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

C#
protected void ChangeProfile_Click(object sender, EventArgs e)
        {
            if (FileUpload1.PostedFile != null)
            {
                /* Get a reference to PostedFile object */
                HttpPostedFile attFile = FileUpload1.PostedFile;
                /* Get size of the file */
                int attachFileLength = attFile.ContentLength;
                /* Make sure the size of the file is > 0  */
                if (attachFileLength > 0)
                {
                    /* Get the file name */
                    strFileName = Path.GetFileName(FileUpload1.PostedFile.FileName);
                    /* Save the file on the server */
                    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
            {
                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();
                con1.Close();
            }
            }

           
        }
Posted
Updated 7-May-14 22:30pm
v3
Comments
DamithSL 8-May-14 4:15am    
any exception?
jayraj86 8-May-14 4:29am    
no error.. When i change image it gets updated but not other fields

Debug.
SqlCommand cmd1 = new SqlCommand(str1, con1);
Capture the string str1 above and then run it in SQL Server Management Studio to cnofirm if the query is working.
 
Share this answer
 
Comments
jayraj86 8-May-14 4:18am    
I tried writing Response.write("text") in else section but it doesnt show on click. I have not chosen any file to upload here
Did you get value at firstname.Text, lastname.Text? etc...
 
Share this answer
 
Comments
jayraj86 11-May-14 10:28am    
yes i m getting values in text boxes

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