Solved

use order by command in dataset

Posted on 2007-12-06
6
423 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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Wpf develop 5 35
Library to convert HTML to PDF. 8 46
display data in text field from data base for updating 6 29
C# TextBox 11 15
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…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

746 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

12 Experts available now in Live!

Get 1:1 Help Now