TroubleShotting working with Data Set
-
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 ***********/
-
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 ***********/
-
Please tell me more about why do you remove and then re-add the table TableName. This can't make sense! Stefan
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 ***********/
-
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 ***********/
-
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
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 ***********/
-
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 ***********/
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?
-
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?
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 ***********/
-
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 ***********/