?
Solved

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

Posted on 2004-11-22
5
Medium Priority
?
313 Views
Last Modified: 2006-11-17
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
0
Comment
Question by:cbasulto
5 Comments
 
LVL 4

Expert Comment

by:rlibrandi
ID: 12647424
You need to define what datatype you want your function to return

 <WebMethod()> Public Function UserDisplayName(ByVal strLogin As String) AS String
0
 

Author Comment

by:cbasulto
ID: 12647651
  Still same error with:
 <WebMethod()> Public Function UserDisplayName(ByVal strLogin As String) As String...
0
 

Author Comment

by:cbasulto
ID: 12647667
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.
0
 
LVL 3

Accepted Solution

by:
weddell earned 2000 total points
ID: 12649746
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
0
 

Expert Comment

by:jbarbara
ID: 12654485
Weddell is correct
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
No other job is as rewarding and demanding as building an iPhone app is. It is not really in the hands of the developer for the success of an iPhone app. Many factors operate jointly for every iOS application's success in the market.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses
Course of the Month12 days, 17 hours left to enroll

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question