Click here to Skip to main content
15,905,616 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have got a dataset.
C#
DataSet dataSet2 = new DataSet();

            SqlConnection conStr2 = new SqlConnection(ConStr);

            string queryString = "Select * FROM JoinTable";

            SqlDataAdapter daGlobalClass2 = new SqlDataAdapter(queryString, conStr2);

            conStr2.Open();

            daGlobalClass2.Fill(dataSet2, "myDataTable");

            conStr2.Close();


Mytable has 5 columns. One of them are TableA. Now I want to sort the dataset on the basis of column TableA. If the value of TableA is "mostusedtable" then those row will come first.

In the following way I can sort dataset.

C#
datatables1.DefaultView.Sort = "TableA";


But how can I sort this dataset on the basis of the value of column TableA ?
Posted
Updated 2-Mar-15 23:53pm
v3

Please, read the documentation: Filtering and Sorting Directly in Data Tables[^]
 
Share this answer
 
If you want to sort the data table:

C#
DataView view = datatables1.DefaultView;
view.Sort = "TableA";
DataTable sortedTable = view.ToTable();


If you want to sort de datagrid:

C#
    dataGrid1.Sort(dataGrid1.Colums[<index>]);
</index>
 
Share this answer
 
Hi,

You Need to add Another calculated Column in Select Query

like

SQL
string queryString = "
select (SELECT p.[Rows] FROM sys.tables t INNER JOIN   sys.indexes i ON t.OBJECT_ID = i.object_id INNER JOIN sys.partitions p ON i.object_id = p.OBJECT_ID AND i.index_id = p.index_id WHERE t.NAME = tblRes.TableA AND i.OBJECT_ID > 255 AND i.index_id <= 1 ) as RowCount, tblRes.* from JoinTable as tblRes "


Then Sort That Data Table By RowCount Column

SQL
datatables1.DefaultView.Sort = "RowCount";



Thanks

Siva Rm K
 
Share this answer
 
Try This Code

DataView dv = ft.DefaultView;
dv.Sort = "occr desc";
DataTable sortedDT = dv.ToTable();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900