check for function return type

Discussion in 'ASP .Net' started by =?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?=, Jul 29, 2005.

  1. I have a function that returns a dataset or a boolean depending upon whether
    a record was found. I can check for the string value of the return type, but
    i don'r think this is the right way to do it what is the correct method?
    any help would be appreciated.
    (hey, i'm actually learning how to do this "-------"!
    FUNCTION:
    ' this function will return the a dataset with the current user if
    the loogin was successful else if will return a false
    Dim DsUser1 As dsUser = New dsUser
    Me.SqlDataAdapter1.SelectCommand.Parameters(1).Value = thsUserID
    Me.SqlDataAdapter1.SelectCommand.Parameters(2).Value = thsPassword
    Me.SqlDataAdapter1.Fill(DsUser1.usr)
    If DsUser1.usr.Count = 0 Then
    Return False
    Else
    Return DsUser1
    End If
    End Function
    function call
    If IsValid Then
    Try
    Dim us As UserServices = New UserServices
    Dim usrResult As Object
    usrResult = us.fn_Isvalid(Me.txtUserID.Text,
    Me.txtPassword.Text)
    Me.lblMSG.Text = usrResult.GetType.ToString()
    If usrResult.GetType = System.Boolean
    Me.lblStatus.Text = User not valid
    ELSE
    Me.lblStatue.text = usrREsult.usrUserID
    End If

    Catch ex As Exception
    .......
    End Try
    End If

    thanks
    kes
    =?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?=, Jul 29, 2005
    #1
    1. Advertising

  2. =?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?=

    Marina Guest

    Your function should not be declared as Object. If Option Strict is not on -
    turn it on. And always keepp it on.

    You can declare the function as returning a dataset, and then return
    Nothing, if no rows came back. You will just have to test the result of the
    call to see if it's Nothing. If it is, no user was found, otherwise you can
    safely use the dataset that was returned.

    "WebBuilder451" <> wrote in message
    news:...
    >I have a function that returns a dataset or a boolean depending upon
    >whether
    > a record was found. I can check for the string value of the return type,
    > but
    > i don'r think this is the right way to do it what is the correct method?
    > any help would be appreciated.
    > (hey, i'm actually learning how to do this "-------"!
    > FUNCTION:
    > ' this function will return the a dataset with the current user if
    > the loogin was successful else if will return a false
    > Dim DsUser1 As dsUser = New dsUser
    > Me.SqlDataAdapter1.SelectCommand.Parameters(1).Value = thsUserID
    > Me.SqlDataAdapter1.SelectCommand.Parameters(2).Value = thsPassword
    > Me.SqlDataAdapter1.Fill(DsUser1.usr)
    > If DsUser1.usr.Count = 0 Then
    > Return False
    > Else
    > Return DsUser1
    > End If
    > End Function
    > function call
    > If IsValid Then
    > Try
    > Dim us As UserServices = New UserServices
    > Dim usrResult As Object
    > usrResult = us.fn_Isvalid(Me.txtUserID.Text,
    > Me.txtPassword.Text)
    > Me.lblMSG.Text = usrResult.GetType.ToString()
    > If usrResult.GetType = System.Boolean
    > Me.lblStatus.Text = User not valid
    > ELSE
    > Me.lblStatue.text = usrREsult.usrUserID
    > End If
    >
    > Catch ex As Exception
    > ......
    > End Try
    > End If
    >
    > thanks
    > kes
    Marina, Jul 29, 2005
    #2
    1. Advertising

  3. thanks,
    i was hoping for some flexability with return types but, well.........
    thanks you again
    kes

    "Marina" wrote:

    > Your function should not be declared as Object. If Option Strict is not on -
    > turn it on. And always keepp it on.
    >
    > You can declare the function as returning a dataset, and then return
    > Nothing, if no rows came back. You will just have to test the result of the
    > call to see if it's Nothing. If it is, no user was found, otherwise you can
    > safely use the dataset that was returned.
    >
    > "WebBuilder451" <> wrote in message
    > news:...
    > >I have a function that returns a dataset or a boolean depending upon
    > >whether
    > > a record was found. I can check for the string value of the return type,
    > > but
    > > i don'r think this is the right way to do it what is the correct method?
    > > any help would be appreciated.
    > > (hey, i'm actually learning how to do this "-------"!
    > > FUNCTION:
    > > ' this function will return the a dataset with the current user if
    > > the loogin was successful else if will return a false
    > > Dim DsUser1 As dsUser = New dsUser
    > > Me.SqlDataAdapter1.SelectCommand.Parameters(1).Value = thsUserID
    > > Me.SqlDataAdapter1.SelectCommand.Parameters(2).Value = thsPassword
    > > Me.SqlDataAdapter1.Fill(DsUser1.usr)
    > > If DsUser1.usr.Count = 0 Then
    > > Return False
    > > Else
    > > Return DsUser1
    > > End If
    > > End Function
    > > function call
    > > If IsValid Then
    > > Try
    > > Dim us As UserServices = New UserServices
    > > Dim usrResult As Object
    > > usrResult = us.fn_Isvalid(Me.txtUserID.Text,
    > > Me.txtPassword.Text)
    > > Me.lblMSG.Text = usrResult.GetType.ToString()
    > > If usrResult.GetType = System.Boolean
    > > Me.lblStatus.Text = User not valid
    > > ELSE
    > > Me.lblStatue.text = usrREsult.usrUserID
    > > End If
    > >
    > > Catch ex As Exception
    > > ......
    > > End Try
    > > End If
    > >
    > > thanks
    > > kes

    >
    >
    >
    =?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?=, Jul 29, 2005
    #3
  4. how would you check for nothing?
    thanks again!!!
    kes

    "Marina" wrote:

    > Your function should not be declared as Object. If Option Strict is not on -
    > turn it on. And always keepp it on.
    >
    > You can declare the function as returning a dataset, and then return
    > Nothing, if no rows came back. You will just have to test the result of the
    > call to see if it's Nothing. If it is, no user was found, otherwise you can
    > safely use the dataset that was returned.
    >
    > "WebBuilder451" <> wrote in message
    > news:...
    > >I have a function that returns a dataset or a boolean depending upon
    > >whether
    > > a record was found. I can check for the string value of the return type,
    > > but
    > > i don'r think this is the right way to do it what is the correct method?
    > > any help would be appreciated.
    > > (hey, i'm actually learning how to do this "-------"!
    > > FUNCTION:
    > > ' this function will return the a dataset with the current user if
    > > the loogin was successful else if will return a false
    > > Dim DsUser1 As dsUser = New dsUser
    > > Me.SqlDataAdapter1.SelectCommand.Parameters(1).Value = thsUserID
    > > Me.SqlDataAdapter1.SelectCommand.Parameters(2).Value = thsPassword
    > > Me.SqlDataAdapter1.Fill(DsUser1.usr)
    > > If DsUser1.usr.Count = 0 Then
    > > Return False
    > > Else
    > > Return DsUser1
    > > End If
    > > End Function
    > > function call
    > > If IsValid Then
    > > Try
    > > Dim us As UserServices = New UserServices
    > > Dim usrResult As Object
    > > usrResult = us.fn_Isvalid(Me.txtUserID.Text,
    > > Me.txtPassword.Text)
    > > Me.lblMSG.Text = usrResult.GetType.ToString()
    > > If usrResult.GetType = System.Boolean
    > > Me.lblStatus.Text = User not valid
    > > ELSE
    > > Me.lblStatue.text = usrREsult.usrUserID
    > > End If
    > >
    > > Catch ex As Exception
    > > ......
    > > End Try
    > > End If
    > >
    > > thanks
    > > kes

    >
    >
    >
    =?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?=, Jul 29, 2005
    #4
  5. sorry, found my own answer
    If usrResult Is Nothing Then
    Me.lblStatus.Text = "user is not valid"
    Else
    Me.lblStatus.Text = usrResult.usr(0).usrLName
    End If
    IOU1!!!
    thanks
    kes

    "WebBuilder451" wrote:

    > how would you check for nothing?
    > thanks again!!!
    > kes
    >
    > "Marina" wrote:
    >
    > > Your function should not be declared as Object. If Option Strict is not on -
    > > turn it on. And always keepp it on.
    > >
    > > You can declare the function as returning a dataset, and then return
    > > Nothing, if no rows came back. You will just have to test the result of the
    > > call to see if it's Nothing. If it is, no user was found, otherwise you can
    > > safely use the dataset that was returned.
    > >
    > > "WebBuilder451" <> wrote in message
    > > news:...
    > > >I have a function that returns a dataset or a boolean depending upon
    > > >whether
    > > > a record was found. I can check for the string value of the return type,
    > > > but
    > > > i don'r think this is the right way to do it what is the correct method?
    > > > any help would be appreciated.
    > > > (hey, i'm actually learning how to do this "-------"!
    > > > FUNCTION:
    > > > ' this function will return the a dataset with the current user if
    > > > the loogin was successful else if will return a false
    > > > Dim DsUser1 As dsUser = New dsUser
    > > > Me.SqlDataAdapter1.SelectCommand.Parameters(1).Value = thsUserID
    > > > Me.SqlDataAdapter1.SelectCommand.Parameters(2).Value = thsPassword
    > > > Me.SqlDataAdapter1.Fill(DsUser1.usr)
    > > > If DsUser1.usr.Count = 0 Then
    > > > Return False
    > > > Else
    > > > Return DsUser1
    > > > End If
    > > > End Function
    > > > function call
    > > > If IsValid Then
    > > > Try
    > > > Dim us As UserServices = New UserServices
    > > > Dim usrResult As Object
    > > > usrResult = us.fn_Isvalid(Me.txtUserID.Text,
    > > > Me.txtPassword.Text)
    > > > Me.lblMSG.Text = usrResult.GetType.ToString()
    > > > If usrResult.GetType = System.Boolean
    > > > Me.lblStatus.Text = User not valid
    > > > ELSE
    > > > Me.lblStatue.text = usrREsult.usrUserID
    > > > End If
    > > >
    > > > Catch ex As Exception
    > > > ......
    > > > End Try
    > > > End If
    > > >
    > > > thanks
    > > > kes

    > >
    > >
    > >
    =?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?=, Jul 29, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Greenhorn
    Replies:
    15
    Views:
    796
    Keith Thompson
    Mar 6, 2005
  2. Diego Martins
    Replies:
    5
    Views:
    475
    Diego Martins
    Sep 5, 2006
  3. NotGuru
    Replies:
    3
    Views:
    423
    NotGuru
    Mar 24, 2008
  4. Luca Forlizzi
    Replies:
    4
    Views:
    444
    Luca Forlizzi
    Nov 14, 2010
  5. andrew cooke
    Replies:
    1
    Views:
    178
    Steven D'Aprano
    Apr 3, 2011
Loading...

Share This Page