asp.net为什么修改textbox的内容(返回页面有显示更改的数据),但是数据库更新不了,求救啊!~!
在浏览器上测试没有检测出问题,就是跟新不了数据

解决方案 »

  1.   

      8成是页面的Page_Load 的 !IsPostBack  没设置
      

  2.   

    我看是九成
    if (!IsPostBack)
            { }
      

  3.   

     已经设置过 !IsPostBack
    if (IsPostBack)
            {
                //实例化Connection对象
                using (connection = new SqlConnection("Data Source=.;Initial Catalog=classnewssystem;Persist Security Info=True;User ID=sa;Password=123"))
                {//实例化Command对象
                    using (SqlCommand command = new SqlCommand("select * from Information where Sname=@SName", connection))
                    {
                        command.Parameters.AddWithValue("@SName", "小小");
                        adapter = new SqlDataAdapter(command);
                        data = new DataTable();
                       
                        adapter.Fill(data);
                        data.PrimaryKey = new DataColumn[] { data.Columns["Sno"] };
                        data.Rows[0].BeginEdit();
                        data.Rows[0]["Sno"] = number.Text;
                        data.Rows[0]["Sname"] = name.Text;
                        data.Rows[0]["Ssex"] = sex.Text;
                        data.Rows[0]["Sage"] =this.age.Text;
                        data.Rows[0].EndEdit();
                        data.AcceptChanges();
                        adapter.Update(data); 
                    }
                  }
              }
      

  4.   

    调试,看看number.Text、name.Text、sex.Text的值。
      

  5.   

    if (!IsPostBack)
            {
                //实例化Connection对象
                using (connection = new SqlConnection("Data Source=.;Initial Catalog=classnewssystem;Persist Security Info=True;User ID=sa;Password=123"))
                {//实例化Command对象
                    using (SqlCommand command = new SqlCommand("select * from Information where Sname=@SName", connection))
                    {
                        command.Parameters.AddWithValue("@SName", "小小");
                        adapter = new SqlDataAdapter(command);
                        data = new DataTable();
                        adapter.Fill(data);
                        data.PrimaryKey = new DataColumn[] { data.Columns["Sno"] };
                        this.number.Text = data.Rows[0]["Sno"].ToString();                    name.Text = data.Rows[0]["Sname"].ToString();
                        sex.Text = data.Rows[0]["Ssex"].ToString();
                        age.Text = data.Rows[0]["Sage"].ToString();
                                                         }
                }再次重新声明!IsPostBack 和IsPostBack的情况都写了,运行时修改的值返回页面时有显示,就是数据库没有更新,调试时textbox显示值已经改变
      

  6.   

    你没执行你那sql吧? 没看到执行的代码
      

  7.   


    command.Parameters.AddWithValue("@SName", "小小");
      adapter = new SqlDataAdapter(command);  data.PrimaryKey = new DataColumn[] { data.Columns["Sno"] };
      this.number.Text = data.Rows[0]["Sno"].ToString();  name.Text = data.Rows[0]["Sname"].ToString();
      sex.Text = data.Rows[0]["Ssex"].ToString();
      age.Text = data.Rows[0]["Sage"].ToString();
      data = new DataTable();
      adapter.Fill(data);这样试试
      

  8.   


    adapter.Update(data); 有写更新