|
-
Jan 28th, 2007, 12:57 AM
#1
Thread Starter
New Member
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.
-
Jan 28th, 2007, 01:23 AM
#2
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.
-
Jan 28th, 2007, 01:35 AM
#3
Thread Starter
New Member
Re: DataView Sorting
Thanks for the response but unfortunately the data comes from a flat file so i can not requery the database
-
Jan 28th, 2007, 02:08 AM
#4
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.
-
Jan 28th, 2007, 02:27 AM
#5
Thread Starter
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|