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

Posted on 2011-04-29
Last Modified: 2012-05-11
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.
Question by:silentthread2k
    LVL 14

    Accepted Solution

    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.
    LVL 20

    Expert Comment

    Use a dataview to Sort the Data. DataView.Sort
    LVL 9

    Expert Comment

    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:-
    LVL 9

    Expert Comment

    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();
    DataView dvData = new DataView(dtData);
    dvData.Sort = "country,city";
    gvSort.DataSource = dvData; // gvsort is a Gridview

    Open in new window


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
    Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
    Via a live example, show how to shrink a transaction log file down to a reasonable size.
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    759 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

    11 Experts available now in Live!

    Get 1:1 Help Now