Returning a DataSet from a Web Services

Discussion in 'ASP .Net' started by Boffo Jinko, Nov 7, 2003.

  1. Boffo Jinko

    Boffo Jinko Guest

    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
    Boffo Jinko, Nov 7, 2003
    #1
    1. Advertising

  2. 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)
    > 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
    >
    >
    >.
    >
    Kaustav Neogy, Nov 7, 2003
    #2
    1. Advertising

  3. Boffo Jinko

    Guest Guest

    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)
    > 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
    >
    >
    >.
    >
    Guest, Nov 7, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sumaira Ahmad
    Replies:
    2
    Views:
    414
    bruce barker
    Nov 2, 2004
  2. Sumaira Ahmad

    Please Help me- Returning DataSet from a Web Service

    Sumaira Ahmad, Nov 1, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    114
    Sumaira Ahmad
    Nov 1, 2004
  3. Iain
    Replies:
    9
    Views:
    148
    Rick Spiewak
    Jul 15, 2004
  4. John
    Replies:
    4
    Views:
    439
  5. Hammer
    Replies:
    5
    Views:
    217
    John Saunders
    Sep 28, 2008
Loading...

Share This Page