我写了一个 sql 函数,它返回一个标量:如果密码正确则为 1,否则为 0。
CREATE FUNCTION check_credential( @User_IN nvarchar(50), @Pwd_IN nvarchar(50))
RETURNS int
AS
BEGIN
DECLARE @PwdRES int
DECLARE @PWD_DB varbinary(255)
IF (@User_IN is not null and @User_IN != '' and @Pwd_IN is not null and @Pwd_IN != '' )
begin
SELECT @PWD_DB = password FROM myTable WHERE username = @User_IN
SET @PwdRES = pwdcompare(@Pwd_IN, @PWD_DB )
end
ELSE
SET @PwdRES = 0
RETURN @PwdRES
END
这可以正常工作。
我正在使用以下代码调用 sql 函数:
Dim conn As SqlConnection
Dim sqlcmd As SqlCommand
Dim da As SqlClient.SqlDataAdapter
Dim table As DataTable
Dim Result As Integer
conn = New SqlConnection(ConnectionString)
sqlcmd = New SqlClient.SqlCommand()
sqlcmd.Connection = conn
conn.Open()
sqlcmd.CommandType = CommandType.StoredProcedure
sqlcmd.CommandText = "check_credential"
sqlcmd.Parameters.Add(New SqlClient.SqlParameter("@username", Utilities.NothingToDBNull(user)))
sqlcmd.Parameters.Add(New SqlClient.SqlParameter("@password", Utilities.NothingToDBNull(password)))
此时我想执行 sqlcmd 并获取返回值。