为什么这个 T-SQL 函数总是返回 true?
我写了这个函数,现在它总是返回 true...
有人可以帮助我吗?
Create FUNCTION dbo.ValidateBranch
(
@BranchID nvarchar(50),
@Password nvarchar(50)
)
RETURNS bit
AS
BEGIN
declare @Res bit
if exists(Select * From TPasswords Where (BranchID = @BranchID) and (isSecurity = 0) and (Pass = @Password))
set @Res = 1
else
set @Res = 0
RETURN @Res
END
我这样称呼:
bool isValidBranch = taQueries.ValidateBranch(IDBranch, PasswordTextBox.Text) ?? false;
I wrote this function and now its always returning true...
can anybody help me?
Create FUNCTION dbo.ValidateBranch
(
@BranchID nvarchar(50),
@Password nvarchar(50)
)
RETURNS bit
AS
BEGIN
declare @Res bit
if exists(Select * From TPasswords Where (BranchID = @BranchID) and (isSecurity = 0) and (Pass = @Password))
set @Res = 1
else
set @Res = 0
RETURN @Res
END
and i'm callign like so:
bool isValidBranch = taQueries.ValidateBranch(IDBranch, PasswordTextBox.Text) ?? false;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
T-SQL 代码看起来不错 - 如何“始终返回 true” - 在 SQL Mgmt Studio 中,或者从您的应用程序调用此函数?
你是如何调用这个函数的,你能给我们看看那段代码吗?
我很快重新创建了设置,就我而言,在 SQL Server 2008 R2 上,当我像这样调用此函数时,它工作得很好:
The T-SQL code seems fine - how do you "always get back true" - in SQL Mgmt Studio, or from your app calling this function??
How are you calling this function, can you show us that piece of code??
I quickly recreated the setup and in my case, on SQL Server 2008 R2, it works just fine when I call this function like this: