62,074
社区成员
发帖
与我相关
我的任务
分享
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string KeyId = GridView1.DataKeys[e.RowIndex].Value.ToString();
string DeleteStr = "DELETE FROM Suppliers WHERE SupplierID='" + KeyId + "'";
SqlConnection DeleteCon = new SqlConnection(ConStr);
SqlCommand DeleteCmd = new SqlCommand(DeleteStr, DeleteCon);
try
{
DeleteCon.Open();
DeleteCmd.ExecuteNonQuery();
BindGridView();
Literal TxtMsg = new Literal();
TxtMsg.Text = "<script>alert('删除成功')</script>";
Page.Controls.Add(TxtMsg);
}
catch (Exception ex)
{
Literal TxtMsg = new Literal();
TxtMsg.Text = "<script>alert('删除出错,请检查数据是否有关联')</script>";
Page.Controls.Add(TxtMsg);
}
finally
{
DeleteCon.Dispose();
}
}