SQL部分
ALTER PROCEDURE [dbo].[sp_ChangePassword]
(
@CustID VARCHAR(10),
@OldPassword VARCHAR(10),
@NewPassword VARCHAR(10)
)
AS
IF EXISTS(SELECT * FROM dbo.A_User WHERE CustID=@CustID and [Password]=@OldPassword)
BEGIN
UPDATE dbo.A_user SET [Password]=@NewPassword WHERE CustID=@CustID
SELECT result=1 ---得到表
END
ELSE
BEGIN
SELECT result=0 --得到表
END
-----后台部分
/// <summary>
/// 改变密码
/// </summary>
/// <param name="CustID">编号</param>
/// <param name="oldPassword">旧密码</param>
/// <param name="newPassword">新密码</param>
/// <param name="StoredProcedureName">存储过程名称</param>
/// <returns></returns>
public static int sp_getOldPwd_and_updatePwd(string CustID,string oldPassword,string newPassword, string StoredProcedureName)
{
try
{
//传入参数
SqlParameter[] para = new SqlParameter[3];
para[0] = new SqlParameter("@CustID", typeof(string));
para[0].Value = CustID;
para[1] = new SqlParameter("@OldPassword", typeof(string));
para[1].Value = oldPassword;
para[2] = new SqlParameter("@newPassword", typeof(string));
para[2].Value = newPassword;
return Convert.ToInt32(SqlHelper.ExecuteScalar(strConn,CommandType.StoredProcedure,"sp_ChangePassword",para));
----ExecuteScalar 返回得到第一行第一列 也就是 SELECT result=1 或 SELECT result=0
}
catch (Exception ex)
{
throw ex;
}
}