-
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.
-
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.
-
Re: DataView Sorting
Thanks for the response but unfortunately the data comes from a flat file so i can not requery the database
-
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.
-
Re: DataView Sorting
mine is actually a fixed width smtp log file. but thanks though i will look into that