How to split one dataset into two datatable???
-
Hi All, I have created a dataset which contains 50 records. I want to put the first 20 records in one datatable and the last 30 records into another datatable. I don't know how to do it. anyone has idea? Thanks Tin
-
Hi All, I have created a dataset which contains 50 records. I want to put the first 20 records in one datatable and the last 30 records into another datatable. I don't know how to do it. anyone has idea? Thanks Tin
tinmail wrote:
I have created a dataset which contains 50 records.
Not true. A DataSet is a collection of DataTable objects, which are collections of DataRow objects. You have a DataSet, then contains a DataTable, which contains 50 records. Are these 50 records generated by your code, or are they retrieved from a database?? If retrieved, the problem would be solved by running two queries against the database and have it dump each set on records into seperate DataTable objects. If generated, then it's easier to put the records in the correct table when they are generated, not after.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008 -
tinmail wrote:
I have created a dataset which contains 50 records.
Not true. A DataSet is a collection of DataTable objects, which are collections of DataRow objects. You have a DataSet, then contains a DataTable, which contains 50 records. Are these 50 records generated by your code, or are they retrieved from a database?? If retrieved, the problem would be solved by running two queries against the database and have it dump each set on records into seperate DataTable objects. If generated, then it's easier to put the records in the correct table when they are generated, not after.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008Thanks for your reply, Dave. The dataset is retrieved from database. What I am trying to do is select the Top 50 records in database then show the top 20 into a datalist and the rest in another datalist. I know in SQL server doesn't have the "LIMIT" function. Thats why I don't know how to get those 30 records. Thanks Tin
-
Thanks for your reply, Dave. The dataset is retrieved from database. What I am trying to do is select the Top 50 records in database then show the top 20 into a datalist and the rest in another datalist. I know in SQL server doesn't have the "LIMIT" function. Thats why I don't know how to get those 30 records. Thanks Tin
2 easy options. 1 use a dataview for each datalist (not a control I know of) applying an appropriate rowfilter. 2 use the same rowfilters and user copytotable on the filtered dataview, then use the seperate tables for the datalist. 3rd one user linq to filter the datatable binding the resultset to the datalist - I seperate this as I have limited experience with linq.
Never underestimate the power of human stupidity RAH
-
Thanks for your reply, Dave. The dataset is retrieved from database. What I am trying to do is select the Top 50 records in database then show the top 20 into a datalist and the rest in another datalist. I know in SQL server doesn't have the "LIMIT" function. Thats why I don't know how to get those 30 records. Thanks Tin
tinmail wrote:
I know in SQL server doesn't have the "LIMIT" function.
Not really true. You could create your dataset with 2 tables (like Dave referred to earlier): DataSet Orders Table (top 20 customers) Table2 (bottom 30 customers). You would then use a 'Select TOP' and an ORDER BY statement to order the records however you want (maybe combined with a group by) and do the fills. Top 20 highest Select top 20 * From Customers order by AR Balance Bottom 30 Select top 30 * From Customers order by AR Balance desc Personally, I would just fill one datatable and use a dataview to filter the rows vs filling two tables.
Any suggestions, ideas, or 'constructive criticism' are always welcome. "There's no such thing as a stupid question, only stupid people." - Mr. Garrison