Returning a DataSet from a Web Services

  • Thread starter Thread starter Boffo Jinko
  • Start date Start date
B

Boffo Jinko

This should be obvious, but I can't figure it out...

I have the following web service:

<WebMethod (Description:="Returns a dataset of all people from the
database.")> _
Public Function GetAllPeople() As DataSet

Dim objConn As New OleDbConnection(Application("dbString"))
Dim cmd As New OleDbCommand("persondata.all_people", objConn)
cmd.CommandType = CommandType.StoredProcedure
Dim da As New OleDbDataAdapter(cmd)
Dim dsTemp As New DataSet
objConn.Open()
da.Fill(dsTemp, "AllJudges")
Return dsTemp
End Function

From an ASP.NET project, I have referenced the web service and have declared
it.

Private objPeopleService As MyService.Service1
...
objPeopleService = New MyService.Service1
Dim objDs As DataSet = objPeopleService.GetAllPeople
Response.Write("<br>Count is " &
objDs.Tables("Exchanges").Rows.Count)

The Reponse.Write() line gives an error: Object reference not set to an
instance of an object

If I call a WebMethod that returns an integer, it returns fine. I created a
test WebMethod that gets a DataSet and then returns the count from the
WebMethod, as opposed to passing the DataSet back to the client, and it
returns the count just fine. So it looks like I am doing something wrong
either in the WebMethod Return statement or in assigning the DataSet a value
in the client. Any ideas about what the problem is?

Thank you!
Scott
 
Hi Scott,

try this -

Dim objDs As New DataSet()
objDs = objPeopleService.GetAllPeople

Kaustav Neogy.


-----Original Message-----
This should be obvious, but I can't figure it out...

I have the following web service:

<WebMethod (Description:="Returns a dataset of all people from the
database.")> _
Public Function GetAllPeople() As DataSet

Dim objConn As New OleDbConnection(Application ("dbString"))
Dim cmd As New OleDbCommand
("persondata.all_people", objConn)
 
The problem is that when you fill the dataset, you call
it "AllJudges" and when you try to get the count you are
trying to reference it by "Exchanges".

If you change the names so they match, your code should
work. Another way to make this work if you are expecting
only one table would be to use the index of the table.
In this case you would use... objDs.Tables(0).Rows.Count

Good Luck,

Keith

-----Original Message-----
This should be obvious, but I can't figure it out...

I have the following web service:

<WebMethod (Description:="Returns a dataset of all people from the
database.")> _
Public Function GetAllPeople() As DataSet

Dim objConn As New OleDbConnection(Application ("dbString"))
Dim cmd As New OleDbCommand
("persondata.all_people", objConn)
 
Back
Top