datagrid 删除和更新
程序如下:
protected void dgd_users_DeleteCommand(object source, DataGridCommandEventArgs e)
{
string strconn = "server=localhost;uid=sa;pwd=sa;database=购物 ";
SqlConnection cn = new SqlConnection(strconn);
cn.Open();
SqlCommand cm = new SqlCommand( "UserDelete ", cn);
cm.CommandType = CommandType.StoredProcedure;
cm.Parameters.Add( "@UID ", SqlDbType.VarChar);
cm.Parameters[ "@UID "].Value = e.Item.Cells[0].Text.ToString();
cm.ExecuteNonQuery();
dgd_users.EditItemIndex = -1;
BindGrid();
}
protected void dgd_users_UpdateCommand(object source, DataGridCommandEventArgs e)
{
string strconn = "server=localhost;uid=sa;pwd=sa;database=购物 ";
SqlConnection cn = new SqlConnection(strconn);
cn.Open();
string mysql = "update Users set UPower=@UPower where UID=@UID ";
SqlCommand cm = new SqlCommand(mysql, cn);
cm.Parameters.Add( "@UPower ", SqlDbType.Int);
cm.Parameters.Add( "@UID ", SqlDbType.VarChar);
cm.Parameters[ "@UPower "].Value=e.Item.Cells[1].Text.ToString();
cm.Parameters[ "@UID "].Value = e.Item.Cells[0].Text.ToString();
cm.ExecuteNonQuery();
dgd_users.EditItemIndex = -1;
BindGrid();
}
其中UserDelete存储过程为:
CREATE PROCEDURE UserDelete
(@UID [varchar])
as delete [购物].[dbo].Users
where
([UID]=@UID)
GO
编译可以通过,但是使用的时候就是什么效果都没有,高手来救救啊,赶时间。。谢谢~~~
------解决方案--------------------你可以跟踪以下,不过
存储过程的删除有问题
少from
------解决方案--------------------1. 在cm.ExecuteNonQuery();后面记得加cn.Close();
2. 看看你的Page_Load是否是这样写的
private void Page_Load(object s