none
is sorting required after sorting in database or a new datatable is created after inserting record in an order at run time in asp.net RRS feed

  • Question

  • Dear All

    Please tel me is sorting required on page  ".aspx" again. in following cases?

    from point 1,2,5) we are using datatable , dataset to store in  session .

    to bind grid we bind it with datatable,dataset and dataview when filttering is required.

    1)i am getting sorted data from database and keeping it in session then from session i take it out and bind the grid .

    2)i am getting sorted data from database and keep it in session then from session i take it out and bind the grid with view after filltering .

    3)i am getting sorted data from database and binding the grid directally.

    4) i am creating a new datatable and adding rows at runtime in a order and then i bind it to grid. should i sort again.

    5)i am getting sorted data from database into dataset or datatable and using foreach to iterate datatable, will it iterate in same order in which i got it from database.

    6)i am getting sorted data from database and keep the dataset or datatable  in session then we take it out to use foreach ,will it iterate in same order in which i got it from database.

    please consider above case with and with out typed dataset.

    yours sincerely

    Tuesday, May 8, 2012 9:42 AM

All replies

  • Hi rajemessage,

    Based on my understanding, It seems all the cases should work.

    If the records ordered in database, it must order in your dataset or datatable.

    About DataView, the Sort method also work: http://msdn.microsoft.com/en-us/library/b51xae2y(v=vs.71).aspx

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, May 9, 2012 6:55 AM
    Moderator
  • You would never try to sort data in a database and neither in its reflection the DataSet.

    The datatable has a special view for that build in the DataView (the property in the datatable DefaultView)

    You can construct as much extra views as you like with code like this.

    Vb

    dim myView As new DataView(TheDataTable)

    C#

    var myView = new DataView(TheDataTable);


    Success
    Cor


    Wednesday, May 9, 2012 9:37 AM
  • Hi rajemessage,

    Based on my understanding, It seems all the cases should work.

    If the records ordered in database, it must order in your dataset or datatable.

    About DataView, the Sort method also work: http://msdn.microsoft.com/en-us/library/b51xae2y(v=vs.71).aspx

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    thank u , that means 4) point also does not need sorting again as while creating i am creating in order?

    Wednesday, May 9, 2012 1:27 PM
  • Hi rajemessage,

    Based on my understanding, It seems all the cases should work.

    If the records ordered in database, it must order in your dataset or datatable.

    About DataView, the Sort method also work: http://msdn.microsoft.com/en-us/library/b51xae2y(v=vs.71).aspx

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    thank u, that means in  point 4) there is no need of sorting ?
    Wednesday, May 9, 2012 1:39 PM
  • You would never try to sort data in a database and neither in its reflection the DataSet.

    The datatable has a special view for that build in the DataView (the property in the datatable DefaultView)

    You can construct as much extra views as you like with code like this.

    Vb

    dim myView As new DataView(TheDataTable)

    C#

    var myView = new DataView(TheDataTable);


    Success
    Cor


    Kindlly give me one reason for not sorting data in database? so that i can understand.
    Thursday, May 10, 2012 1:13 PM
  • You would never try to sort data in a database and neither in its reflection the DataSet.

    The datatable has a special view for that build in the DataView (the property in the datatable DefaultView)

    You can construct as much extra views as you like with code like this.

    Vb

    dim myView As new DataView(TheDataTable)

    C#

    var myView = new DataView(TheDataTable);


    Success
    Cor


    Kindlly give me one reason for not sorting data in database? so that i can understand.

    There are many reasons, but two of them. 

    A database is made for concurrently (multi user) use of data. So if you are sorting it is never for all end users the same. 

    It takes a lot of time because it has to be done physically, be aware that databases are in fact endless collections of indexes, which probably become with every sort more complex.


    Success
    Cor

    Friday, May 11, 2012 5:39 AM
  • Wait a minute ... there's nothing wrong with doing a "SELECT * from MyTable Order By MyColumn" when you get your data from a database table! Did I misunderstand what you're trying to say Cor?

    ~~Bonnie Berent DeWitt [C# MVP]

    geek-goddess-bonnie.blogspot.com

    Sunday, May 13, 2012 4:51 AM