日期:2014-05-18  浏览次数:20425 次

数据更新问题,没有出错提示,但数据没有更新
[code=C#][/code] protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
  {
  string fmfgodrno = ((Label)GridView1.Rows[e.RowIndex].FindControl("Label14")).Text.Trim().ToString();
  string fusrnote1 = ((Label)GridView1.Rows[e.RowIndex].FindControl("Label17")).Text.Trim().ToString();
  string fkoitemno = ((Label)GridView1.Rows[e.RowIndex].FindControl("Label11")).Text.Trim().ToString();
  string fitemno = ((Label)GridView1.Rows[e.RowIndex].FindControl("Label2")).Text.Trim().ToString();
  string mfitemln = ((Label)GridView1.Rows[e.RowIndex].FindControl("Label12")).Text.Trim().ToString();
  string fvendinvc = ((Label)GridView1.Rows[e.RowIndex].FindControl("Label8")).Text.Trim().ToString();
  string fitemln = ((Label)GridView1.Rows[e.RowIndex].FindControl("Label1")).Text.Trim().ToString();
  string num = Server.HtmlDecode(((TextBox)GridView1.Rows[e.RowIndex].Cells[7].Controls[1]).Text.ToString());
  string lotno = Server.HtmlDecode(((TextBox)GridView1.Rows[e.RowIndex].Cells[6].Controls[1]).Text.ToString());
  string updatetime = today.ToString("yyyy/M/d");
  string UpdateStr = "update xianpinpiao set lotno ='" + lotno + "',num = '" + num + "',updatetime= '" + updatetime + "' where orderno = '" + fmfgodrno + "' and mlotno = '" + fvendinvc + "'";
  UpdateStr += " and lotno='" + lotno + "'";

  SqlConnection conn1 = new SqlConnection("Data Source=.;Initial Catalog=nikko;Integrated Security=True");
  conn1.Open();
  try
  {
  SqlCommand cmd = new SqlCommand(UpdateStr, conn1);
  int number = cmd.ExecuteNonQuery();
  }
  catch
  {
  this.Page.RegisterStartupScript("msg", "<script>alert('输入的数据有误!')</script>");
  }
  finally
  {
  conn1.Close();
  }
  GridView1.EditIndex = -1;
  this.Bind();
  }

------解决方案--------------------
1.把GridView1_RowUpdated中的代码删除掉测试
2.
 try
{
SqlCommand cmd = new SqlCommand(UpdateStr, conn1);
int number = cmd.ExecuteNonQuery();
}
catch
{
this.Page.RegisterStartupScript("msg", "<script>alert('输入的数据有误!')</script>");
e.cannel=true;
Response。End();
}

这么写测试下
------解决方案--------------------
是没插入到数据库 还是没显示出来哦? page_load里绑定数据源的时候记得写在 if(!IsPostBack){}里。。