GridView为何无法更新,帖代码了帮我看下吧
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OracleClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
GV1();
}
//数据绑定到控件
private void GV1()
{
OracleConnection conn = new OracleConnection( "Data Source=xx;User ID=xx;Password=xx; ");
conn.Open();
OracleDataAdapter oradar = new OracleDataAdapter( "SELECT XMBH , XMMC , JSDW , JSDD , HPPZSJ , HPPW FROM XM order by HPPZSJ ", conn);
DataSet da = new DataSet();
oradar.Fill(da, "XM ");
GridView1.DataSource = da.Tables[ "XM "].DefaultView;
GridView1.DataKeyNames = new string[] { "XMBH " };//必须指定主键,否则删除语句会报错
GridView1.DataBind();
conn.Close();
}
//点击编辑进入到编辑状态
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
GV1();
}
//删除一行
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
OracleConnection conn = new OracleConnection( "Data Source=xx;User ID=xx;Password=xx; ");
string strSQL = "delete from XM where XMBH= ' " + GridView1.DataKeys[e.RowIndex].Value.ToString() + " ' ";
OracleCommand cmd = new OracleCommand(strSQL, conn);
conn.Open();
cmd.Execute