Translating Columns As Rows In a DataSet

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jumping Matt Flash

    Translating Columns As Rows In a DataSet

    The code i'm writing is using VB .NET and is for a web service returning a
    dataset, which is in turn to be used by an ASP .NET application displaying a
    datagrid.

    I'm currently populating a datagrid using a "select top 1 column 1, column2,
    column3 from tblTable" statement. As there will only ever be one row
    returned I want to be able to to switch the column names to be row1 and the
    column values to be row 2

    i.e. select house, street, state from table addresses

    16, Washington Way, NYC

    to be displayed as

    ELEM VAL
    ------- -------
    House 16
    Street Washington Way
    State NYC


    To make this translation easiest i want to be able to do this using my web
    service. Any ideas as to how i can manipulate my dataset in such a way?

    TIA,
    Matt


  • Ken Tucker [MVP]

    #2
    Re: Translating Columns As Rows In a DataSet

    Hi,



    Ken
    ------------------
    "Jumping Matt Flash" <jumpingmattfla sh@gmail.com> wrote in message
    news:%23kVcqxok FHA.3692@TK2MSF TNGP09.phx.gbl. ..
    The code i'm writing is using VB .NET and is for a web service returning a
    dataset, which is in turn to be used by an ASP .NET application displaying a
    datagrid.

    I'm currently populating a datagrid using a "select top 1 column 1, column2,
    column3 from tblTable" statement. As there will only ever be one row
    returned I want to be able to to switch the column names to be row1 and the
    column values to be row 2

    i.e. select house, street, state from table addresses

    16, Washington Way, NYC

    to be displayed as

    ELEM VAL
    ------- -------
    House 16
    Street Washington Way
    State NYC


    To make this translation easiest i want to be able to do this using my web
    service. Any ideas as to how i can manipulate my dataset in such a way?

    TIA,
    Matt



    Comment

    • Jumping Matt Flash

      #3
      Re: Translating Columns As Rows In a DataSet

      Many thanks Ken,

      However i've continued to have issues with your code for some reason. As i'm
      retrieving only the one row i've tried using the following: Draw is a web
      service which returns a dataset according to inString

      Dim dataTables = Accessor.Draw(i nString)
      Dim dt2 As New DataTable("Tran slated")
      dataTables.Tabl es.Add(dt2)

      'Loop table(0) translating the data
      Dim dr As DataRow = dataTables.Tabl es(1).NewRow
      For y As Integer = 0 To dataTables.Tabl es(0).Columns.C ount - 1
      dr(y) = dataTables.Tabl es(0).Rows(0).I tem(y)
      Next
      dataTables.Tabl es(1).Rows.Add( dr)

      This just returns the following error however:

      Exception Details: System.IndexOut OfRangeExceptio n: Cannot find column 0.

      Source Error:

      Line 34: Dim dr As DataRow = dataTables.Tabl es(1).NewRow
      Line 35: For y As Integer = 0 To
      dataTables.Tabl es(0).Columns.C ount - 1
      Line 36: dr(y) = dataTables.Tabl es(0).Rows(0).I tem(y)
      Line 37: Next
      Line 38: dataTables.Tabl es(1).Rows.Add( dr)


      TIA

      Matt

      "Ken Tucker [MVP]" <vb2ae@bellsout h.net> wrote in message
      news:uHr$F%23ok FHA.1948@TK2MSF TNGP12.phx.gbl. ..[color=blue]
      > Hi,
      >
      > http://www.windowsformsdatagridhelp....8-2b9e762316ab
      >
      > Ken
      > ------------------
      > "Jumping Matt Flash" <jumpingmattfla sh@gmail.com> wrote in message
      > news:%23kVcqxok FHA.3692@TK2MSF TNGP09.phx.gbl. ..
      > The code i'm writing is using VB .NET and is for a web service returning a
      > dataset, which is in turn to be used by an ASP .NET application displaying
      > a
      > datagrid.
      >
      > I'm currently populating a datagrid using a "select top 1 column 1,
      > column2,
      > column3 from tblTable" statement. As there will only ever be one row
      > returned I want to be able to to switch the column names to be row1 and
      > the
      > column values to be row 2
      >
      > i.e. select house, street, state from table addresses
      >
      > 16, Washington Way, NYC
      >
      > to be displayed as
      >
      > ELEM VAL
      > ------- -------
      > House 16
      > Street Washington Way
      > State NYC
      >
      >
      > To make this translation easiest i want to be able to do this using my web
      > service. Any ideas as to how i can manipulate my dataset in such a way?
      >
      > TIA,
      > Matt
      >
      >
      >[/color]


      Comment

      • Ken Tucker [MVP]

        #4
        Re: Translating Columns As Rows In a DataSet

        Hi,

        I am not sure why you are getting the error. However I would stop
        using late binding it might help find your error.

        Dim dataTables as dataset = Accessor.Draw(i nString)


        Ken
        -----------------
        "Jumping Matt Flash" <jumpingmattfla sh@gmail.com> wrote in message
        news:%23glHjdpk FHA.2904@tk2msf tngp13.phx.gbl. ..
        Many thanks Ken,

        However i've continued to have issues with your code for some reason. As i'm
        retrieving only the one row i've tried using the following: Draw is a web
        service which returns a dataset according to inString

        Dim dataTables = Accessor.Draw(i nString)
        Dim dt2 As New DataTable("Tran slated")
        dataTables.Tabl es.Add(dt2)

        'Loop table(0) translating the data
        Dim dr As DataRow = dataTables.Tabl es(1).NewRow
        For y As Integer = 0 To dataTables.Tabl es(0).Columns.C ount - 1
        dr(y) = dataTables.Tabl es(0).Rows(0).I tem(y)
        Next
        dataTables.Tabl es(1).Rows.Add( dr)

        This just returns the following error however:

        Exception Details: System.IndexOut OfRangeExceptio n: Cannot find column 0.

        Source Error:

        Line 34: Dim dr As DataRow = dataTables.Tabl es(1).NewRow
        Line 35: For y As Integer = 0 To
        dataTables.Tabl es(0).Columns.C ount - 1
        Line 36: dr(y) = dataTables.Tabl es(0).Rows(0).I tem(y)
        Line 37: Next
        Line 38: dataTables.Tabl es(1).Rows.Add( dr)


        TIA

        Matt

        "Ken Tucker [MVP]" <vb2ae@bellsout h.net> wrote in message
        news:uHr$F%23ok FHA.1948@TK2MSF TNGP12.phx.gbl. ..[color=blue]
        > Hi,
        >
        > http://www.windowsformsdatagridhelp....8-2b9e762316ab
        >
        > Ken
        > ------------------
        > "Jumping Matt Flash" <jumpingmattfla sh@gmail.com> wrote in message
        > news:%23kVcqxok FHA.3692@TK2MSF TNGP09.phx.gbl. ..
        > The code i'm writing is using VB .NET and is for a web service returning a
        > dataset, which is in turn to be used by an ASP .NET application displaying
        > a
        > datagrid.
        >
        > I'm currently populating a datagrid using a "select top 1 column 1,
        > column2,
        > column3 from tblTable" statement. As there will only ever be one row
        > returned I want to be able to to switch the column names to be row1 and
        > the
        > column values to be row 2
        >
        > i.e. select house, street, state from table addresses
        >
        > 16, Washington Way, NYC
        >
        > to be displayed as
        >
        > ELEM VAL
        > ------- -------
        > House 16
        > Street Washington Way
        > State NYC
        >
        >
        > To make this translation easiest i want to be able to do this using my web
        > service. Any ideas as to how i can manipulate my dataset in such a way?
        >
        > TIA,
        > Matt
        >
        >
        >[/color]



        Comment

        • Phill.  W

          #5
          Re: Translating Columns As Rows In a DataSet

          "Jumping Matt Flash" <jumpingmattfla sh@gmail.com> wrote in message
          news:%23kVcqxok FHA.3692@TK2MSF TNGP09.phx.gbl. ..[color=blue]
          > The code i'm writing is using VB .NET and is for a web service
          > returning a dataset, which is in turn to be used by an ASP .NET
          > application displaying a datagrid.[/color]

          From the little I know of WebServices, returning a DataSet is a
          Bad Idea. Web Services are meant for cross-platform interoperabilit y
          (can hardly type it, let alone pronounce it!), and only .Net clients can
          seriously make use of the amorphous DataSet.
          Anyhow ...
          [color=blue]
          > I'm currently populating a datagrid using a "select top 1 column 1,
          > column2, column3 from tblTable" statement. As there will only ever
          > be one row returned I want to be able to to switch the column names
          > to be row1 and the column values to be row 2[/color]

          This really shouldn't be an issue for the WebService.
          Return your DataSet with one row and, containing the data, and pull
          the item "names" out of the Column Names. Let the Presentation layer
          (the ASP.Net thing) get all het up about how to display the thing.

          If you make the WebService too complicated, you'll kick yourself
          when you start trying to pass the same data back in again and have
          to "unpick" all your meticulous rearranging.

          Regards,
          Phill W.


          Comment

          • Cor Ligthert [MVP]

            #6
            Re: Translating Columns As Rows In a DataSet

            Phill,
            [color=blue]
            > From the little I know of WebServices, returning a DataSet is a
            > Bad Idea.[/color]

            In my opinion only true as the next rule is true as well.
            [color=blue]
            >Web Services are meant for cross-platform interoperabilit y
            > (can hardly type it, let alone pronounce it!), and only .Net clients can
            > seriously make use of the amorphous DataSet.[/color]

            However when we tell that we are talking about .Net programs, than there is
            again cross-platform interoperabilit y.

            A dataset is very nice to use in a webservice you know.

            Just my thought.

            Cor


            Comment

            • Cor Ligthert [MVP]

              #7
              Re: Translating Columns As Rows In a DataSet

              Jumping Matt

              Although it is possible in the an aspnet application to use a webservice,
              are you in my idea overdoing it.

              If you use a webservice from somebody else it has a lot of sense. However
              now are you everytime visiting your webserver to get information, that you
              can get direct. In my opinion a little bit inefficient operation that only
              creates more clients.

              However just my thought,

              Cor


              Comment

              Working...