问题描述
我在编程中使用commandfield列自动生成编辑,更新,取消列,但是代码写完以后更新功能无法实现.点击更新之后,数据没有被修改,代码如下,请大虾们指正.具体程序功能是,首先查询信息,然后编辑里的修改.usingSystem;usingSystem.Data;usingSystem.Configuration;usingSystem.Collections;usingSystem.Web;usingSystem.Web.Security;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.Web.UI.WebControls.WebParts;usingSystem.Web.UI.HtmlControls;usingSystem.Data.SqlClient;publicpartialclassZTZCX_BMMCX:System.Web.UI.Page{protectedvoidPage_Load(objectsender,EventArgse){}protectedvoidButton2_Click(objectsender,EventArgse){Response.Redirect("ZTZCX.aspx");}DataSetGetDataSet(){SqlConnectionmycon=newSqlConnection();mycon.ConnectionString="DataSource=.;InitialCatalog=SBGL;IntegratedSecurity=True";mycon.Open();SqlCommandsel=newSqlCommand("SELECTDISTINCT*FROMNEWSBTZWHERESBH='"+TextBox1.Text+"'",mycon);SqlDataAdapterda=newSqlDataAdapter();da.SelectCommand=sel;DataSetds=newDataSet();da.Fill(ds,"NEWSBTZ");mycon.Close();returnds;}voidLoadData(){DataSethw=GetDataSet();GridView1.DataSource=hw;GridView1.DataBind();}protectedvoidButton1_Click(objectsender,EventArgse){GetDataSet();LoadData();}protectedvoidGridView1_RowEditing(objectsender,GridViewEditEventArgse){GridView1.EditIndex=e.NewEditIndex;LoadData();}protectedvoidGridView1_RowUpdating(objectsender,GridViewUpdateEventArgse){SqlConnectionmycon=newSqlConnection();mycon.ConnectionString="DataSource=.;InitialCatalog=SBGL;IntegratedSecurity=True";mycon.Open();SqlCommandmyxg=newSqlCommand();myxg.Connection=mycon;stringsql="UPDATENEWSBTZSETZJLY='"+((TextBox)GridView1.Rows[e.RowIndex].Cells[0].Controls[0]).Text+"'WHEREZCH='"+GridView1.Rows[e.RowIndex].Cells[3].Text+"'";myxg.CommandText=sql;myxg.ExecuteNonQuery();mycon.Close();GridView1.EditIndex=-1;LoadData();protectedvoidGridView1_RowCancelingEdit(objectsender,GridViewCancelEditEventArgse){GridView1.EditIndex=-1;LoadData();}}