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

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
            Return "Invalid"
        End If
    End Function
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

 <WebMethod()> Public Function UserDisplayName(ByVal strLogin As String) AS String
cbasultoAuthor Commented:
  Still same error with:
 <WebMethod()> Public Function UserDisplayName(ByVal strLogin As String) As String...
cbasultoAuthor Commented:
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.
Yep, whenever you see that error - assume you haven't instantiated an object... it's a common mistake made and something ASP developers do all the time.

You have these lines:

Dim ds As DataSet
Dim row As DataRow

You have declared that ds and row have a type of DataSet and DataRow respectively, BUT you have instantiated them.

Dim ds As New DataSet
Dim row As New DataRow

which is a shorthand method of writing:

Dim ds As DataSet = New DataSet
Dim row As DataRow = New DataRow

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Weddell is correct
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Development

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.