ASP.NET C# DataGrid里如何实现删除
我想在DataGrid里点一下删除就能删除一行但是点完之后没有反映……
求人帮忙解决
先谢谢了
附上代码:
public void MyDataGrid_Delete(Object sender, DataGridCommandEventArgs e)
{
//建立数据库连接
OleDbConnection myConnection = new OleDbConnection("Provider=sqloledb;server=(local);database=information;uid=sa;pwd=sa");
//定义删除SQL语句
String deleteCmd = "delete from Content where id = @id";
OleDbCommand myCommand = new OleDbCommand(deleteCmd, myConnection);
myCommand.Parameters.Add(new OleDbParameter("@id", OleDbType.Char, 11));
myCommand.Parameters["@id"].Value = MyList.DataKeys[(int)e.Item.ItemIndex];
myCommand.Connection.Open();
try
{
myCommand.ExecuteNonQuery();
}
catch (OleDbException)
{
}
myCommand.Connection.Close();
//重新绑定数据,并显示
DataBind();
}
下面是图片:
[[it] 本帖最后由 b25921 于 2009-7-29 11:49 编辑 [/it]]