我的数据库中有一个UserAcount
表。在Profile
页面中,用户可以更新其信息。如果Password
已填写,我必须更新它,否则我只是更新其他字段。
我这样做,但发生以下错误:
过程或函数'EditUserInfo'需要参数'@Password',这是未提供的。
ALTER PROCEDURE EditUserInfo
(
@FirstName NVARCHAR(100),
@LastName NVARCHAR(200),
@UserName NVARCHAR(100),
@Password BINARY
)
AS
BEGIN
IF (@Password IS NULL)
BEGIN
UPDATE UserAcount
SET FirstName = @FirstName,
LastName = @LastName
WHERE UserName = @UserName
END
ELSE
BEGIN
UPDATE UserAcount
SET FirstName = @FirstName,
LastName = @LastName,
[password] = @Password
WHERE UserName = @UserName
END
END
你能帮我吗?
答案 0 :(得分:3)
你可以添加" = NULL"在@password参数之后。
alter procedure EditUserInfo
(@FirstName nvarchar(100),
@LastName nvarchar(200),
@UserName nvarchar(100),
@Password binary = NULL
)
as
begin
if (@Password IS NULL)
BEGIN
UPDATE UserAcount
SET
FirstName = @FirstName ,
LastName = @LastName
where UserName = @UserName
END
ELSE
BEGIN
UPDATE UserAcount
SET
FirstName = @FirstName ,
LastName = @LastName,
[Password] = @Password
where UserName = @UserName
END
end
答案 1 :(得分:2)
ALTER PROCEDURE dbo.EditUserInfo
(
@FirstName NVARCHAR(100),
@LastName NVARCHAR(200),
@UserName NVARCHAR(100),
@Password BINARY = NULL
)
AS BEGIN
SET NOCOUNT ON
UPDATE dbo.UserAcount
SET FirstName = @FirstName,
LastName = @LastName,
Password = ISNULL(@Password, Password)
WHERE UserName = @UserName
END