无法更新按钮单击的数据。 asp.net [英] Not able to update data on button click. asp.net

查看:86
本文介绍了无法更新按钮单击的数据。 asp.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含一个文件上传控件的表单。在页面加载我将数据库中的所有数据加载到表单的相应文本框中。



我有一个更新按钮,但点击我的数据没有更新。下面是我的更新按钮代码

当我更改图像时它会更新但不会更新其他字段





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

推荐答案

在不知道应用程序的相关其他代码的情况下,很难说出上述代码的问题是什么数据库结构。

如下所示,

1.在两种方法的下面行创建断点

It is difficult to tell what is the issue with above code without knowing related other code of your application and the database structure.
Do as below,
1. create breakpoint on below line of both methods
SqlCommand cmd = new SqlCommand(str, con);



2.运行你的应用程序并检查它是否达到了断点正如所料。如果应用程序遇到其中一个断点,请检查sql语句的值并在SQL Server上手动运行sql语句。你可以通过这样做来确认sql语句是正确还是错误。如果您发现任何问题,请回到VS并进行更改或询问有关您的调查结果的详细信息。如果你有任何例外,你需要在提问时包括所有这些细节。

去读取掌握Visual Studio 2010中的调试 - 初学者指南 [ ^ ]


这篇关于无法更新按钮单击的数据。 asp.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆