关于vs05 的gridview使用 80
publicpartialclass_Default:System.Web.UI.Page{OleDbConnectionsqlcon;OleDbCommandsqlco...
public partial class _Default : System.Web.UI.Page
{
OleDbConnection sqlcon;
OleDbCommand sqlcom;
// string strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+server.mappath("."+\dbdb\global.mdb) ;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bind();
}
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
bind();
}
//删除
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
try
{
string sqlstr = "delete from grade where 学号=" + GridView1.DataKeys[e.RowIndex].Value.ToString();
Response.Write("<script language=javascript>alert('成功删除!')</script>");
sqlcon = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;"+"Data Source="+Server.MapPath("person.mdb"));
sqlcom = new OleDbCommand(sqlstr,sqlcon);
sqlcon.Open();
sqlcom.ExecuteNonQuery();
sqlcon.Close();
bind();
}
catch (Exception ex)
{
Response.Write(ex.Message);
Response.Write("<script language=javascript>alert('删除失败!')</script>");
}
} 展开
{
OleDbConnection sqlcon;
OleDbCommand sqlcom;
// string strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+server.mappath("."+\dbdb\global.mdb) ;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bind();
}
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
bind();
}
//删除
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
try
{
string sqlstr = "delete from grade where 学号=" + GridView1.DataKeys[e.RowIndex].Value.ToString();
Response.Write("<script language=javascript>alert('成功删除!')</script>");
sqlcon = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;"+"Data Source="+Server.MapPath("person.mdb"));
sqlcom = new OleDbCommand(sqlstr,sqlcon);
sqlcon.Open();
sqlcom.ExecuteNonQuery();
sqlcon.Close();
bind();
}
catch (Exception ex)
{
Response.Write(ex.Message);
Response.Write("<script language=javascript>alert('删除失败!')</script>");
}
} 展开
3个回答
展开全部
private void bind()
{
sqlcon = new OleDbConnection (strCon );
sqlcom = new OleDbCommand ("Select * From grade",sqlcon );
sqlcon.Open();
OleDbDataReader dr = sqlcom.ExecuteReader();
GridView1.DataSource = dr;
GridView1.DataKeyNames = new string[]{"学号"};
GridView1.DataBind();
dr.Close();
sqlcon.Close();
}
{
sqlcon = new OleDbConnection (strCon );
sqlcom = new OleDbCommand ("Select * From grade",sqlcon );
sqlcon.Open();
OleDbDataReader dr = sqlcom.ExecuteReader();
GridView1.DataSource = dr;
GridView1.DataKeyNames = new string[]{"学号"};
GridView1.DataBind();
dr.Close();
sqlcon.Close();
}
ZESTRON
2024-09-04 广告
2024-09-04 广告
在Dr. O.K. Wack Chemie GmbH,我们高度重视ZESTRON的表界面分析技术。该技术通过深入研究材料表面与界面的性质,为提升产品质量与可靠性提供了有力支持。ZESTRON的表界面分析不仅涵盖了相变化、化学反应、吸附与解吸...
点击进入详情页
本回答由ZESTRON提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询