删除存储过程已经写好
CREATE PROCEDURE SP_DelClass (@ID VARCHAR(50))AS
Delete FROM Cuser WHERE id=@ID
GO
在C#里怎么去调用 并执行这段存储过程
CREATE PROCEDURE SP_DelClass (@ID VARCHAR(50))AS
Delete FROM Cuser WHERE id=@ID
GO
在C#里怎么去调用 并执行这段存储过程
public override bool DeleteUser(int id)
{
bool ds = false;
using (SqlConnection conn = GetConnection())
{
SqlCommand cmd = new SqlCommand("SP_DelClass", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@ID", SqlDbType.VarChar, 50).Value = id;
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.DeleteCommand = cmd;
}
return ds;
//throw new Exception("The method or operation is not implemented.");
}
{
int i = 0;
using (SqlConnection conn = GetConnection())
{
SqlCommand cmd = new SqlCommand("SP_DelClass", conn);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter mypara = new SqlParameter("@ID",id);
cmd.Parameters.Add(mypara);
i = cmd.ExecuteNonQuery();
}
return i; //返回受影响的行数
}
{
using (SqlConnection conn = GetConnection())
{
bool ds = false;
SqlCommand cmd = new SqlCommand("SP_DelClass", conn);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter mypara = new SqlParameter("@ID",id);
cmd.Parameters.Add(mypara);
try{
cmd.ExecuteNonQuery();
ds = true;
}
catch
{
ds = fasle;
}
}
return ds; //返回bool值
}