• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 431
  • Last Modified:

use order by command in dataset

hi there ,
i have dataset whit 1 table in it
the dataset fill from a winform datagrid that bind to the ds
after the user insert some rows to the grid he update the dataset
i need to send the dataset to print so i need to use order by command on the rows that exsisit in the dataset on the fly how can i do it in the dataset itself ?

thanks ...

Open in new window

0
Tech_Men
Asked:
Tech_Men
  • 3
  • 3
1 Solution
 
the_b1ackfoxCommented:
Either you can modify the sqladapter query with the order by statement, and when you update the dataset to the database, the new data in the ds will be sorted... or  read below...

You can't do it directly but you can use dataview to do sorting.
You can try the following code..

SqlConnection cn;
cn=new SqlConnection(ConnectionString);
cn.Open();
SqlDataAdapter da;
DataSet ds=new DataSet();
da=new SqlDataAdapter("select emp_id, fname, lname from employee",cn);
da.Fill(ds);

DataView dtView = ds.Tables[0].DefaultView;
dtView.Sort = "fname ASC";

DataGrid1.DataSource=dtView;
DataGrid1.DataBind();
0
 
Tech_MenAuthor Commented:
its must be a wey that i can sort the rows in the ds on the fly
0
 
the_b1ackfoxCommented:
You are using  c# 2003 correct?
0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
Tech_MenAuthor Commented:
yes
0
 
the_b1ackfoxCommented:
I just double checked (reviewed the DS object) and it occurred to me why you will not be able to sort in the ds.  Sorting is a function of viewable data.  As you cannot view a DS directly, you will not be able to sort it's data unless the data is presorted via a query (in which case it is the Database which is doing the sorting not the DS) or sorted by a component designed to show the data.
0
 
Tech_MenAuthor Commented:
thanks ....
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now