protected void OnRowUpdatingEvent(Object sender, GridViewUpdateEventArgs e)
    {
        //Response.Write("<script>alert('" + ds.Tables["图书借阅"].Rows[e.RowIndex]["借阅编号"].ToString() + "!')</script>");
        int res = -1;
        if (updateCmd == null || GridView1 == null)
            return;
        try
        {
           // for (int i = 0; i < 6; i++)
          //      Response.Write("<script>alert('" + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[0].Controls[0])).Text.ToString().Trim() + "!')</script>");            updateCmd.CommandText = @"UPDATE 图书借阅 SET 读者编号=" + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim() + ",图书编号=" + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString().Trim()
            + ",借阅时间='" + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim() + "',应还时间='" + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[4].Controls[0])).Text.ToString().Trim() + "',剩余可续借次数=" + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[5].Controls[0])).Text.ToString().Trim() + " WHERE 借阅编号=" + ds.Tables["图书借阅"].Rows[e.RowIndex]["借阅编号"].ToString() + ";";
            
            updateCmd.Connection = conn;
            res = updateCmd.ExecuteNonQuery();
            //updateCmd.CommandText.Replace('\'', 'x');
            //Response.Write("<script>alert(' res = " + updateCmd.CommandText + "!')</script>");
            Response.Write("<script>alert(' res = " + res.ToString() + "!')</script>");
        }catch(Exception ex)
        {
            Response.Write("<script>alert('" + ex.ToString() + "!')</script>");
        }
                GridView1.EditIndex = -1;
        Bind();
    }
protected void Bind()
    {
        adapter.SelectCommand.CommandText = @"SELECT * FROM 图书借阅";
        if (ds.Tables["图书借阅"] != null)
            ds.Tables["图书借阅"].Clear();        adapter.Fill(ds, "图书借阅");
        GridView1.DataSource = ds.Tables["图书借阅"];
        GridView1.DataBind();
    }
返回受影响行数为1,但数据库中的值并没有改变是怎么回事?

解决方案 »

  1.   

    受影响的行数是符合where条件的记录数吧  你把sql语句 改成这样看效果如何
    UPDATE 图书借阅 SET 读者编号='999',图书编号=" + ((TextBox)(......
      

  2.   

    有可能是ispostback在作怪吧,你有可能是page_load里面绑定数据信息,但是没有加if(!ispostback)判断,导致每次提交的时候,数据还是没有改变之前的
      

  3.   

    断点一下
    跟踪出来sql语句。
    去数据库里执行一下。
    看看是哪里的问题