Solved

use order by command in dataset

Posted on 2007-12-06
6
427 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 

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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
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…

733 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