check for function return type

G

Guest

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
 
M

Marina

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.
 
G

Guest

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

Guest

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,525
Members
44,997
Latest member
mileyka

Latest Threads

Top