Last post Oct 07, 2011 09:32 PM by Decker Dong - MSFT
Oct 06, 2011 01:47 AM|ryanlcs|LINK
I got one master datatable with lots of record, let's say 5000, and in my apps, I wanted to have another datatable which will select the values from this master datatable (maybe i will select certain records from it), and from this second datatable, i will
do some data manipulation.
I know that using DataRow can achieve it, but I want to use a datatable instead of data table.
Oct 06, 2011 01:56 AM|iGulfam|LINK
Simply iterate through parent Datatable. Check the condition for adding record in 2nd Datatable. If condition is true then create a new Datarow object of child datatable. Assign Parent row values to the Datarow object and then add the Datarow to your 2nd
Datatable. At the end of loop you will be having all of your required records in 2nd Datatable.
Oct 06, 2011 02:13 AM|kedarrkulkarni|LINK
you might want to look at DataTable.select method
or datatable.defaultview.rowfilter property
or look at the multiple solutions to filter datatable records
hope this helps...
Oct 07, 2011 09:32 PM|Decker Dong - MSFT|LINK
but I want to use a datatable instead of data table.
In fact, I think you can try to use Stored Procedure and with the help of SqlCommand's ExecuteNonQuery() to deal with the problem——
alter procedure XXX
select * into Your New Table from xxx Name where Your condition……
And then use your codes like this:
using (SqlCommand cmd = new SqlCommand("Your Stored Procedure Name",new SqlConnection("Your Conn Str's Name"))
//Then you can use another SqlDataAdapter to get the new table's value and fill into your DataTable..... Or just do what you want.