Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 346
  • Last Modified:

Is there way way to setup an order by on a SQLDataAdapter

I'm using C# and the SQLDataAdapter to run a query from an MS Sql server.

For crazy managment reasons at work, I cannot add an order by in my actuall select statement, so that is why I need to know if I can do an order by with the SQLDataAdapter before I bind it to a datatable.
0
silentthread2k
Asked:
silentthread2k
  • 2
1 Solution
 
systanCommented:
AS far as I understand,   you can make another table for a temporary storage of ordered items.
Save the temporary orders on that table then for final storage?, save it to the fix final table, then delete records from temporary orders.
0
 
informaniacCommented:
Use a dataview to Sort the Data. DataView.Sort
0
 
mayank_joshiCommented:
you can create a dataview from datatable. The dataview can be used to sort data and
You can bind it to any control just like a dataset or datatable.

this article explains sorting in dataview:-
http://www.knowdotnet.com/articles/dataviewsort.html
0
 
mayank_joshiCommented:
here is an example of binding a sorted dataview to a gridview  :-

string sqlQuery = "SELECT * from [Location]";
SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
SqlDataAdapter sda = new SqlDataAdapter(sqlQuery, conn);
DataTable dtData = new DataTable();
sda.Fill(dtData);

DataView dvData = new DataView(dtData);
dvData.Sort = "country,city";

gvSort.DataSource = dvData; // gvsort is a Gridview
gvSort.DataBind();

Open in new window


0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

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