日期:2014-05-17  浏览次数:20521 次

求助:gridview的编辑事件出了问题
我的代码:

 protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
  {
  GridView1.EditIndex = e.NewEditIndex;//单击一次“编辑”按钮
  string sql = string.Format("select * from WEBGIS08");
  refreshDgv(sql, true);
  }
  protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
  {
   
  string sqlStr = "update WEBGIS08 set TELEPHONE='" 
  + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim() + "',WORKID='"
  + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString().Trim() + "' ,SEX='" 
  + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim() + "' ,BIRTHDAY='" 
  + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[4].Controls[0])).Text.ToString().Trim() + "' ,QQ='" 
  + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[5].Controls[0])).Text.ToString().Trim() + "' ,where NAME='"  
  + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[0].Controls[0])).Text.ToString().Trim() + "'"; 
   
  OracleCommand cmd=new OracleCommand (sqlStr ,DBcon .myConn );
  DBcon .myConn .Open ();
  int rowCount= cmd .ExecuteNonQuery();
  DBcon .myConn .Close ();
  if (rowCount >0)
  {
  GridView1 .EditIndex =-1;
  string sql1=string .Format ("select * from WEBGIS08");
  refreshDgv (sql1 ,true );
  }
   
  }

  protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
  {
  string sql=string .Format ("select * from WEBGIS08 ");
  refreshDgv (sql,true );}


refreshDgv方法:
public void refreshDgv(string sql,bool flag)
  {
  try
  {
  DataSet thisDataSet = new DataSet();
  OracleDataAdapter thisAdapter = new OracleDataAdapter(sql, DBcon.myConn);
  thisDataSet.Clear();
  DBcon.myConn.Open();
  //填充DataSet中的Datatable
  thisAdapter.Fill(thisDataSet, "WEBGIS08");

  DataTable dataTable;
  dataTable = thisDataSet.Tables[0].Copy();
  GridView1.Visible = true;
  GridView1.DataSource = dataTable;
  GridView1 .DataSourceID =null;//很重要,在前台和后台都定义了DatasourceId,必须放弃一个定义,否则会提示“重复定义了”
  GridView1 .DataBind ();  
  }
  catch(OracleException ex)
  {
  throw ex ;  
  }
  finally 
  {
  DBcon .myConn .Close ();
   
  }
运行后,更新操作无效,在 int rowCount= cmd .ExecuteNonQuery();出现ORA-01747: user.table.column, table.column 或列说明无效,我检查了表的列名命名应该没问题,而且上述select语句也没找出语法错误,我该咋办呢?


------解决方案--------------------
写sql时,字段名加[]
------解决方案--------------------
在string sqlStr = "update WEBGIS08 set TELEPHONE='" 设置一个断点,获取到sqlstr,在数据库里面执行。
------解决方案--------------------
这种情况我也遇到过,在你page_load中加上!IsPostBack
C# code