Updatecommand更新结果返回影响值>0,但为什么数据还是没改变?

Jim Wong 2010-12-22 11:08:28
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,但数据库中的值并没有改变是怎么回事?
...全文
113 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
spiderwolf2010 2010-12-22
  • 打赏
  • 举报
回复
可能更新进去的值和原来的一样。
zhaowanru19 2010-12-22
  • 打赏
  • 举报
回复
断点一下
跟踪出来sql语句。
去数据库里执行一下。
看看是哪里的问题
hookyzlr 2010-12-22
  • 打赏
  • 举报
回复
有可能是ispostback在作怪吧,你有可能是page_load里面绑定数据信息,但是没有加if(!ispostback)判断,导致每次提交的时候,数据还是没有改变之前的
asdfg_ 2010-12-22
  • 打赏
  • 举报
回复
受影响的行数是符合where条件的记录数吧 你把sql语句 改成这样看效果如何
UPDATE 图书借阅 SET 读者编号='999',图书编号=" + ((TextBox)(......

62,042

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧