Solved

use order by command in dataset

Posted on 2007-12-06
6
424 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

932 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now