点击gridview控件的删除时没反应?
我用asp.net+access做一个gridview的例子,点击删除时它只是将页面刷新了一下,所选数据行却没被删除?这是为什么?请各位大虾帮忙找一下我错在哪里,多谢了!...
我用asp.net+access做一个gridview的例子,点击删除时它只是将页面刷新了一下,所选数据行却没被删除? 这是为什么? 请各位大虾帮忙找一下我错在哪里,多谢了!下面是我的运行结果和相关代码:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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.OleDb;
public partial class banji_chaxun1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if((int)Session["qx"]<1)
Response.Redirect("/WebSite3/login.aspx");
if(!IsPostBack)
{
bind();
}
}
public void bind()
{
string s = "Provider=microsoft.jet.oledb.4.0;data source=" + Server.MapPath("~") + "\\Tree.mdb";
OleDbConnection conn = new OleDbConnection(s);
OleDbDataAdapter da = new OleDbDataAdapter("select * from Class", conn);
OleDbCommandBuilder cmd = new OleDbCommandBuilder(da);
DataSet ds = new DataSet();
da.Fill(ds, "Class");
GridView1.DataSource = ds.Tables["Class"];
GridView1.DataKeyNames = new string[] {"BanID"};
GridView1.DataBind();
conn.Close();
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string s = "provider=microsoft.jet.oledb.4.0;data source=" + Server.MapPath("~") + "\\Tree.mdb";
string sl = "delete from Student where BanID=" + GridView1.DataKeys[e.RowIndex].Value.ToString();
OleDbConnection conn = new OleDbConnection(s);
conn.Open();
OleDbCommand cmd = new OleDbCommand(sl, conn);
cmd.ExecuteNonQuery();
conn.Close();
bind();
}
} 展开
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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.OleDb;
public partial class banji_chaxun1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if((int)Session["qx"]<1)
Response.Redirect("/WebSite3/login.aspx");
if(!IsPostBack)
{
bind();
}
}
public void bind()
{
string s = "Provider=microsoft.jet.oledb.4.0;data source=" + Server.MapPath("~") + "\\Tree.mdb";
OleDbConnection conn = new OleDbConnection(s);
OleDbDataAdapter da = new OleDbDataAdapter("select * from Class", conn);
OleDbCommandBuilder cmd = new OleDbCommandBuilder(da);
DataSet ds = new DataSet();
da.Fill(ds, "Class");
GridView1.DataSource = ds.Tables["Class"];
GridView1.DataKeyNames = new string[] {"BanID"};
GridView1.DataBind();
conn.Close();
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string s = "provider=microsoft.jet.oledb.4.0;data source=" + Server.MapPath("~") + "\\Tree.mdb";
string sl = "delete from Student where BanID=" + GridView1.DataKeys[e.RowIndex].Value.ToString();
OleDbConnection conn = new OleDbConnection(s);
conn.Open();
OleDbCommand cmd = new OleDbCommand(sl, conn);
cmd.ExecuteNonQuery();
conn.Close();
bind();
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询