Question : how do i do i return the @exist from the function and do this code

           Using connection As New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
                Using command As New SqlCommand("Fn_User_Exist_Usuario", connection)
                    command.CommandType = Data.CommandType.StoredProcedure

                    Dim myParam1 As New SqlParameter("@USUARIO", VarChar, 150)
                    myParam1.Direction = Data.ParameterDirection.Input
                    myParam1.Value = UserName
                    command.Parameters.Add(myParam1)
                    connection.Open()
                    command.ExecuteNonQuery()
                    Dim Exist As Boolean =  /// what i should do here??????? /////
                    If Exist = True Then
                        Return True
                    Else
                        Return False
                    End If
                End Using
            End Using
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER FUNCTION [dbo].[Fn_User_Exist_Usuario](@USUARIO VARCHAR(150))
RETURNS int
AS
Begin
	DECLARE @Exist int
    IF exists(SELECT TOP 1 USUARIO FROM TB_USER WHERE USUARIO = @USUARIO)
    begin
        Set @Exist = 1
    end else begin
        Set @exist = 0
    end;
RETURN @Exist
END

Answer : how do i do i return the @exist from the function and do this code

A function is not a stored procedure...

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
Using connection As New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
                Using command As New SqlCommand("select dbo.Fn_User_Exist_Usuario(@USUARIO)", connection)
                    'text command.CommandType = Data.CommandType.StoredProcedure

                    Dim myParam1 As New SqlParameter("@USUARIO", VarChar, 150)
                    myParam1.Direction = Data.ParameterDirection.Input
                    myParam1.Value = UserName
                    command.Parameters.Add(myParam1)
                    connection.Open()
                    Dim Exist As Boolean = Convert.ToBoolean(command.ExecuteScalar())
                    Return Exist
                End Using
            End Using
Random Solutions  
 
programming4us programming4us