Link to home
Start Free TrialLog in
Avatar of cbasulto
cbasulto

asked on

Object reference not set to an instance of an object : Web Method

Hello,
Getting the error "Object reference not set to an instance of an object" from the following code. Any ideas?

  <WebMethod()> Public Function UserDisplayName(ByVal strLogin As String)
        Dim ds As DataSet
        Dim row As DataRow
        Dim DisplayName As String

        ds.Merge(GetEmployees(0, 0, strLogin))
        row = ds.Tables("Employees").Rows(0)
        If ds.Tables("Employees").Rows.Count = 1 Then
            DisplayName = row("FirstName") & " " & row("LastName")
            Return DisplayName
        Else
            Return "Invalid"
        End If
    End Function
Avatar of rlibrandi
rlibrandi

You need to define what datatype you want your function to return

 <WebMethod()> Public Function UserDisplayName(ByVal strLogin As String) AS String
Avatar of cbasulto

ASKER

  Still same error with:
 <WebMethod()> Public Function UserDisplayName(ByVal strLogin As String) As String...
I have identified where the reference error is occurring;

        ds.Merge(GetEmployees(0, 0, strLogin))

The GetEmployees function is another webmethod in the same service that fetches a dataset with records filtered by input parameters.
ASKER CERTIFIED SOLUTION
Avatar of weddell
weddell

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Weddell is correct