Results 1 to 5 of 5

Thread: DataView Sorting

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2007
    Posts
    9

    DataView Sorting

    I have a datatable that I have already filled up. I then assigned it to a dataset and bound it to a datagrid. This is all working perfectly.

    I know how to do simple sort with a dataview. What i want to be able to do is something like a SQL statement.

    I know theres a sqlclient.sqlcommand. I just don't know how to or if its even possible to use it to do a sql query on a dataview.

    The whole point of this is i need to group by one of my fields in my datatable and also sort by one of them at the same time.

    Any help would be appreciated.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: DataView Sorting

    Firstly, if you already have a populated DataTable then adding it to a DataSet is pointless. You can bind a lone DataTable to a control without the need for a DataSet at all. A DataSet is useful if you want to set up data binding in the designer, you have several tables or you need to specify relationships between tables. If you have a single DataTable you created in code then a dataSet serves no useful purpose.

    As to your question, you cannot do what you're asking for. You can sort and/or filter your data through a DataView. You also have the DataTable.Select method that will get a filtered and (optionally) sorted array of rows from your table. There is also the DataTable.Compute method that will calculate an aggregate function on a single column. That's basically it. There is no inbuilt mechanism to execute full queries on an existing DataTable. You'd have to write the code yourself, or else just hit the database again.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2007
    Posts
    9

    Re: DataView Sorting

    Thanks for the response but unfortunately the data comes from a flat file so i can not requery the database

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: DataView Sorting

    You can use ADO.NET with delimited text files too, so maybe you can. With the appropriate connection string you can connect to a delimited text file using OleDb, just like an Access database. CSV files are a breeze. Other delimiters take a little more effort but are still fairly easy. Some funky, custom format will mess that all up though. That's why standard formats like CSV are a good idea.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    New Member
    Join Date
    Jan 2007
    Posts
    9

    Re: DataView Sorting

    mine is actually a fixed width smtp log file. but thanks though i will look into that

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width