BoulderBum
Programmer
I have a stored SQL Server function fnValidate that I want to call in my code-behind, but I can't figure out how it's supposed to work.
So far, I have this:
String useName = txtUserName.Value;
myCommand = new SqlCommand( "fnValidate", myConnection );
SqlParameter pUserName = new SqlParameter( "@userN", SqlDbType.Char, 20 );
SqlParameter pPassword = new SqlParameter( "@pass", SqlDbType.Char, 16 );
myCommand.Parameters.Add( pUserName );
myCommand.Parameters.Add( pPassword );
pUserName.Value = useName;
pUserName.Value = pswPassword.Value;
myConnection.Open();
and I'm trying to do something like:
if( myCommand.ExecuteScalar() == 1 )
//do something
but it doesn't work. I've also tried calling:
if( myCommand.ExecuteScalar().Equals( 1 ) )
//do something
but I keep getting the error message:
Line 1: Incorrect syntax near 'fnValidate'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Line 1: Incorrect syntax near 'fnValidate'.
What am I doing wrong?
Oh, here's the stored function:
CREATE FUNCTION fnValidate( @userN char(20), @pass char(16) )
RETURNS int
AS
BEGIN
declare @retVal int
IF @userN = null
set @retVal = 0
ELSE IF ( SELECT client_password FROM user_info WHERE client_user_name = @userN ) = @pass
set @retVal = 1
ELSE
set @retVal = 0
RETURN @retVal
END
So far, I have this:
String useName = txtUserName.Value;
myCommand = new SqlCommand( "fnValidate", myConnection );
SqlParameter pUserName = new SqlParameter( "@userN", SqlDbType.Char, 20 );
SqlParameter pPassword = new SqlParameter( "@pass", SqlDbType.Char, 16 );
myCommand.Parameters.Add( pUserName );
myCommand.Parameters.Add( pPassword );
pUserName.Value = useName;
pUserName.Value = pswPassword.Value;
myConnection.Open();
and I'm trying to do something like:
if( myCommand.ExecuteScalar() == 1 )
//do something
but it doesn't work. I've also tried calling:
if( myCommand.ExecuteScalar().Equals( 1 ) )
//do something
but I keep getting the error message:
Line 1: Incorrect syntax near 'fnValidate'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Line 1: Incorrect syntax near 'fnValidate'.
What am I doing wrong?
Oh, here's the stored function:
CREATE FUNCTION fnValidate( @userN char(20), @pass char(16) )
RETURNS int
AS
BEGIN
declare @retVal int
IF @userN = null
set @retVal = 0
ELSE IF ( SELECT client_password FROM user_info WHERE client_user_name = @userN ) = @pass
set @retVal = 1
ELSE
set @retVal = 0
RETURN @retVal
END