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. TroubleShotting working with Data Set

TroubleShotting working with Data Set

Scheduled Pinned Locked Moved C#
questionhelp
8 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.
  • O Offline
    O Offline
    Om r
    wrote on last edited by
    #1

    Hi all, I'm working in a project that uses DataSets and I found a trouble shotting trying to set up in ordering a column of a table contained in the data set, in order to achive I use DataViews, this DataView works perfecly, then I retun the ordered data to the DataSet and then retun this DataSet as WebMethod but the data does simple not work, do anyone know what is the problem??, here is an code of my development... tnks public DataSet MyMethod(DataSet myDS) { // this data view is working perfecly DataView myDView = new DataView(myDS.Tables[tablename], "", , DataViewRowState.CurrentRows); // I'm doing this remove because if doesn't it causes assignment problems myDS.Tables.Remove(tablename); // I'm trying to assign the ordered data to the DataSet myDS.Tables.Add(myDView.Table); return myDS; } // in this web method does not work properly [WebMethod] public DataSet Test() { ... DataSet DS = MyMethod(myDS) return DS; } /*********** Om@r ***********/

    S 1 Reply Last reply
    0
    • O Om r

      Hi all, I'm working in a project that uses DataSets and I found a trouble shotting trying to set up in ordering a column of a table contained in the data set, in order to achive I use DataViews, this DataView works perfecly, then I retun the ordered data to the DataSet and then retun this DataSet as WebMethod but the data does simple not work, do anyone know what is the problem??, here is an code of my development... tnks public DataSet MyMethod(DataSet myDS) { // this data view is working perfecly DataView myDView = new DataView(myDS.Tables[tablename], "", , DataViewRowState.CurrentRows); // I'm doing this remove because if doesn't it causes assignment problems myDS.Tables.Remove(tablename); // I'm trying to assign the ordered data to the DataSet myDS.Tables.Add(myDView.Table); return myDS; } // in this web method does not work properly [WebMethod] public DataSet Test() { ... DataSet DS = MyMethod(myDS) return DS; } /*********** Om@r ***********/

      S Offline
      S Offline
      STW
      wrote on last edited by
      #2

      Please tell me more about why do you remove and then re-add the table TableName. This can't make sense! Stefan

      O 1 Reply Last reply
      0
      • S STW

        Please tell me more about why do you remove and then re-add the table TableName. This can't make sense! Stefan

        O Offline
        O Offline
        Om r
        wrote on last edited by
        #3

        Stefan, Because if you don't remove it, it results in a read only assign error due to the dependency of the table with the dataview. Yesterday I discover that dataview is in fact a memory pointer table that can not be assigned to any other data struct, try doing a test with a code similar to my code without the removing action and see what happens... Omar /*********** Om@r ***********/

        S 1 Reply Last reply
        0
        • O Om r

          Stefan, Because if you don't remove it, it results in a read only assign error due to the dependency of the table with the dataview. Yesterday I discover that dataview is in fact a memory pointer table that can not be assigned to any other data struct, try doing a test with a code similar to my code without the removing action and see what happens... Omar /*********** Om@r ***********/

          S Offline
          S Offline
          STW
          wrote on last edited by
          #4

          Omar, So please tell me what you want to do practically. I'm sure that you don't have to remove and re-add your table. Maybe I can help you. Stefan

          O 1 Reply Last reply
          0
          • S STW

            Omar, So please tell me what you want to do practically. I'm sure that you don't have to remove and re-add your table. Maybe I can help you. Stefan

            O Offline
            O Offline
            Om r
            wrote on last edited by
            #5

            Stefan I'm using a method class that receive a dataset, the name or index of a table and the name or index of a columname and the order, I need to retrieve the DataSer ordered by the column indicated, I can not doing this in a DataGrid because the data is not going to be a web method and this data is going to passed to other layer in the structure, also I can not handle the order in the data base because this data table is composed by more than one table of diferent data base tables and computed columns, so in resume, I need to return this DataSet (or a new one) but with the table in question ordered, could you help me about this?? Omar /*********** Om@r ***********/

            S 1 Reply Last reply
            0
            • O Om r

              Stefan I'm using a method class that receive a dataset, the name or index of a table and the name or index of a columname and the order, I need to retrieve the DataSer ordered by the column indicated, I can not doing this in a DataGrid because the data is not going to be a web method and this data is going to passed to other layer in the structure, also I can not handle the order in the data base because this data table is composed by more than one table of diferent data base tables and computed columns, so in resume, I need to return this DataSet (or a new one) but with the table in question ordered, could you help me about this?? Omar /*********** Om@r ***********/

              S Offline
              S Offline
              STW
              wrote on last edited by
              #6

              public DataSet YourMethod(String Table, String Column or DataColumn dc) DataTable dt=DataSet.Tables[Table]; DataRow[] rows=dt.Select(strExpr, Sort, RowState) better: DataSet.Tables[Table].DefaultView.Sort="ColumnName DESC"; Perhaps you don't know that you can bind your DataGrid to a DataView, too! DataGrid.DataSource=DataSet[Table].DefaultView; If I did not understand your needs try to reexplain or use another language to tell me. German or French, perhaps?

              O 1 Reply Last reply
              0
              • S STW

                public DataSet YourMethod(String Table, String Column or DataColumn dc) DataTable dt=DataSet.Tables[Table]; DataRow[] rows=dt.Select(strExpr, Sort, RowState) better: DataSet.Tables[Table].DefaultView.Sort="ColumnName DESC"; Perhaps you don't know that you can bind your DataGrid to a DataView, too! DataGrid.DataSource=DataSet[Table].DefaultView; If I did not understand your needs try to reexplain or use another language to tell me. German or French, perhaps?

                O Offline
                O Offline
                Om r
                wrote on last edited by
                #7

                Dear STW Finally I found the solution for my problem, I was pointed to erroneus table and row pointer, here is the complete solution... Basicly I needed a method which receives a dataset, table name, column name and type order and the return the same (or in a diferente dataset) the same table contained in a data set but ordered by meaning of the column name and type order (Desc / Asc), as I told you, I can not simply Bind the DataView value to a DataGrid because I need to pass a DataSet to other upper layer that performs other transformation for this DataSet like formating, including / excluding columns, etc. Also I could not handle it in the data base (ordering directly the table) because the data set table composed by differents source data like computed columns, added columns from other data bases, etc. That's why a needed to handle this in a Data Set form... regards and thanks for all... /************************************************************************/ Private Function OrderTable(DataSet, tablename, columnname, typeorder) As DataSet Dim ds1 As New DataSet Dim dt As DataTable Dim dv As DataView Dim dr1 As DataRow Dim a As Integer Dim drv As DataRowView dv = ds.Tables(0).DefaultView dv.Sort = strCol + " " + strOrder dt = ds.Tables(0).Clone For Each drv In dv dr1 = dt.NewRow For a = 0 To dv.Table.Columns.Count - 1 dr1(a) = drv(a) Next dt.Rows.Add(dr1) Next Dt.tableName=strTabla ds1.Tables.Add(dt) Return ds1 End Function /*******************************************************************/ /*********** Om@r ***********/

                S 1 Reply Last reply
                0
                • O Om r

                  Dear STW Finally I found the solution for my problem, I was pointed to erroneus table and row pointer, here is the complete solution... Basicly I needed a method which receives a dataset, table name, column name and type order and the return the same (or in a diferente dataset) the same table contained in a data set but ordered by meaning of the column name and type order (Desc / Asc), as I told you, I can not simply Bind the DataView value to a DataGrid because I need to pass a DataSet to other upper layer that performs other transformation for this DataSet like formating, including / excluding columns, etc. Also I could not handle it in the data base (ordering directly the table) because the data set table composed by differents source data like computed columns, added columns from other data bases, etc. That's why a needed to handle this in a Data Set form... regards and thanks for all... /************************************************************************/ Private Function OrderTable(DataSet, tablename, columnname, typeorder) As DataSet Dim ds1 As New DataSet Dim dt As DataTable Dim dv As DataView Dim dr1 As DataRow Dim a As Integer Dim drv As DataRowView dv = ds.Tables(0).DefaultView dv.Sort = strCol + " " + strOrder dt = ds.Tables(0).Clone For Each drv In dv dr1 = dt.NewRow For a = 0 To dv.Table.Columns.Count - 1 dr1(a) = drv(a) Next dt.Rows.Add(dr1) Next Dt.tableName=strTabla ds1.Tables.Add(dt) Return ds1 End Function /*******************************************************************/ /*********** Om@r ***********/

                  S Offline
                  S Offline
                  STW
                  wrote on last edited by
                  #8

                  So you make a View and then copy the sorted rows to another DataTable. Your solution is to create a new DataTable. Good luck Stefan

                  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