views:

55

answers:

1

Hi
I wrote this function and now its always returning true...
can anybody help me?


Create FUNCTION dbo.ValidateCenter
(
    @Center_ID  nvarchar(50),
    @Password   nvarchar(50)
)
RETURNS bit
AS
    BEGIN
    declare @Res bit

    if exists(Select * From TPasswords Where (Center_ID = @Center_ID) and (isSecurity = 0) and (Pass = @Password)) 
        set @Res = 1
    else
        set @Res = 0



    RETURN @Res
    END

and i'm callign like so:


bool isValidCenter = taQueries.ValidateCenter(IDCenter, PasswordTextBox.Text) ?? false;
+2  A: 

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:

SELECT dbo.ValidateCenter('Center1', 'Pwd1')  -- return 1 
SELECT dbo.ValidateCenter('Center1', 'Pwd1333')  -- return 0
marc_s
i'm using this in a C# project and added it as a Query in an ADO.Net Dataset... also tested this from SQL Express by executing and passing some existing values and some incorrect values
Dr TJ
@Dr TJ: can you add the C# code that you're using to call this to your question?? I think the T-SQL part should work just fine...
marc_s
@Marc: any idea?
Dr TJ