标题:GridView怎么删除行
取消只看楼主
pietro
Rank: 1
等 级:新手上路
帖 子:54
专家分:0
注 册:2006-9-19
 问题点数:0 回复次数:0 
GridView怎么删除行
我想在GridView里删除行,代码如下:
private void GridViewToBind()
{
OleDbConnection con = new OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:/web/mdb/data.mdb");
con.Open();
OleDbDataAdapter odr = new OleDbDataAdapter();
odr.SelectCommand = new OleDbCommand("select * from login", con);
DataSet ds = new DataSet();
odr.Fill(ds, "emp");
this.GridView1.DataKeyNames = "userID";
this.GridView1.DataSource = ds.Tables["emp"].DefaultView;
this.GridView1.DataBind();
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string userID = this.GridView1.DataKeys[e.RowIndex].ToString();
OleDbConnection con = new OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:/web/mdb/data.mdb");
con.Open();
OleDbCommand cmd = new OleDbCommand("delete from login where userID='" + userID + "'", con);
cmd.ExecuteNonQuery();
this.GridViewToBind();
}


运行错误,提示说无法将类型“string”隐式转换为“string[]”,错误行为:
this.GridView1.DataKeyNames = "userID";


请问怎么写才对???
搜索更多相关主题的帖子: GridView odr Microsoft web quot 
2006-11-19 18:36



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-104047-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.021696 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved