Solved

use order by command in dataset

Posted on 2007-12-06
6
425 Views
Last Modified: 2008-09-12
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
Comment
Question by:Tech_Men
  • 3
  • 3
6 Comments
 
LVL 9

Accepted Solution

by:
the_b1ackfox earned 500 total points
ID: 20418120
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
 

Author Comment

by:Tech_Men
ID: 20418156
its must be a wey that i can sort the rows in the ds on the fly
0
 
LVL 9

Expert Comment

by:the_b1ackfox
ID: 20418167
You are using  c# 2003 correct?
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:Tech_Men
ID: 20418180
yes
0
 
LVL 9

Expert Comment

by:the_b1ackfox
ID: 20418317
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
 

Author Comment

by:Tech_Men
ID: 20418371
thanks ....
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question