Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. What to do if I want to return rows from different tables in ASP.NET WebService

What to do if I want to return rows from different tables in ASP.NET WebService

Scheduled Pinned Locked Moved C#
csharpasp-netandroidquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jasonalien
    wrote on last edited by
    #1

    I am trying to make and Android app with ASP.NET WebService. In WebService, if I want to return values from a single table I know what to do :

    public DataTable GetUserDetails(string userName)
    {
    ....
    return userDetailsTable;
    }

    But I don't know what to do if I want to return values from different tables (a more complex data). Should I use

    List

    or something else? If I use

    List

    , how should I handle it in Android side? Thanks.

    F 1 Reply Last reply
    0
    • J jasonalien

      I am trying to make and Android app with ASP.NET WebService. In WebService, if I want to return values from a single table I know what to do :

      public DataTable GetUserDetails(string userName)
      {
      ....
      return userDetailsTable;
      }

      But I don't know what to do if I want to return values from different tables (a more complex data). Should I use

      List

      or something else? If I use

      List

      , how should I handle it in Android side? Thanks.

      F Offline
      F Offline
      F ES Sitecore
      wrote on last edited by
      #2

      Returning things like DataTable is generally a bad idea, especially if your client needs to be lean and use minimal data resources. When you return a DataTable you get a *lot* of stuff returned, when you are normally just interested in the data. What people normally do is define a class object that represents the bits of data you want to return. So if you want to return a Customer table you'll create a Customer class with properties like ID, FirstName, Surname etc, then in your web method you create a List and for each row of your datatable you'll create a Custom object, populate the properties from the fields, add it to the List and then return the List. This will greatly reduce the amount of data sent to your app, and your app now just sees a simply collection with just the data it needs.

      J 1 Reply Last reply
      0
      • F F ES Sitecore

        Returning things like DataTable is generally a bad idea, especially if your client needs to be lean and use minimal data resources. When you return a DataTable you get a *lot* of stuff returned, when you are normally just interested in the data. What people normally do is define a class object that represents the bits of data you want to return. So if you want to return a Customer table you'll create a Customer class with properties like ID, FirstName, Surname etc, then in your web method you create a List and for each row of your datatable you'll create a Custom object, populate the properties from the fields, add it to the List and then return the List. This will greatly reduce the amount of data sent to your app, and your app now just sees a simply collection with just the data it needs.

        J Offline
        J Offline
        jasonalien
        wrote on last edited by
        #3

        Thank you very much for your reply. Can you tell me how I should make Android could handle List< Customer >? A sample code would be great. Moreover is it a good idea to send List< Customer > and List< Order > at the same time? Thanks a lot.

        F 1 Reply Last reply
        0
        • J jasonalien

          Thank you very much for your reply. Can you tell me how I should make Android could handle List< Customer >? A sample code would be great. Moreover is it a good idea to send List< Customer > and List< Order > at the same time? Thanks a lot.

          F Offline
          F Offline
          F ES Sitecore
          wrote on last edited by
          #4

          No idea TBH, this is a c# forum, I don't know anything about Android apps. Although you are return a List, .net will convert that to json so your Android app should see something like [{ID:1, FirstName: "John", LastName: "Doe"}, {ID=2, FirstName: "Dave", LastName: "Smith"}] whatever framework Android has for calling web services will know how to parse that.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups