Hi I am working on a .NET 3.5 application. I want to select a group of rows from a Table based on the Filter Criteria and move those rows to a new DataTable. Table1 has 100 rows -- > Select the Rows from Table1 if Column1 value is "A" or "B" or "C" - - > Move
the selected Rows to Table2. Is it possible to move few rows from Table1 to Table2 directly without looping the rows? How to select the group of rows from a Table based on Filter and move to a new Table in C# code? I am using OLEDB My code is like this: sourceFile=@"D:\Users\Desktop\New
Data\KO_Consolidated.csv" string strSql = "SELECT * FROM [" + System.IO.Path.GetFileName(sourceFile) + "]"; string strCSVConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + System.IO.Path.GetDirectoryName(sourceFile) + ";" + "Extended Properties='text;HDR=YES;'";
OleDbDataAdapter oleda = new OleDbDataAdapter(strSql, strCSVConnString); DataTable KODATA = new DataTable(); oleda.Fill(KODATA); DataView dv = new DataView(); DataSet ds = new DataSet(); DataColumn column1 = new DataColumn("WorkInfoType", typeof(string));
KODATA.Columns.Add(column1); dv = new DataView(KODATA); dv.RowFilter = "WorkInfoType='Incident Task / Action' AND WorkInfoSummary='KS'"; return KODATA; But i m not able to get my result. Thanks a lot in advance for your help.
So far as I know, we want to move some data records from a dataTable to another dataTable without looping the rows. If my understanding is correct, we can try to copy a dataTable to another dataTable. Please refer to the code below:
//the DataTable1 is the select data with filter criteria.
DataTable DataTable1 = new DataTable();
DataTable DataTable2 = new DataTable();
DataView DataView1 = new DataView();
DataSet DataSet1 = new DataSet();
// Copy the entire DataTable.
DataTable2 = DataTable1.Copy();
DataSet1.Tables.Add(DataTable2);
For more information, please refor to the link below:
girimalla
0 Points
2 Posts
Selecting rows in DataTable based on Filter Criteria in C# with using OLEDB
Aug 30, 2013 06:17 AM|LINK
prk_in
Contributor
2372 Points
480 Posts
Re: Selecting rows in DataTable based on Filter Criteria in C# with using OLEDB
Sep 02, 2013 12:36 PM|LINK
It is possible refer post
http://stackoverflow.com/questions/4883537/how-to-pass-datatable-select-result-to-a-new-datatable
http://stackoverflow.com/questions/16767010/c-sharp-datatable-select-how-do-i-format-the-filter-criteria-to-include-null
About Select Method
http://msdn.microsoft.com/en-us/library/det4aw50.aspx
http://social.msdn.microsoft.com/Forums/vstudio/en-US/1a4a8560-e952-4b4d-87dc-bbfd41ae0b3b/linq-output-selected-columns-to-datatable
Happy Coding !
Please Mark If it helps you || Ramakrishna.p
Michelle Ge ...
Contributor
2593 Points
269 Posts
Microsoft
Re: Selecting rows in DataTable based on Filter Criteria in C# with using OLEDB
Sep 02, 2013 01:49 PM|LINK
Hi,
So far as I know, we want to move some data records from a dataTable to another dataTable without looping the rows. If my understanding is correct, we can try to copy a dataTable to another dataTable. Please refer to the code below:
//the DataTable1 is the select data with filter criteria.
For more information, please refor to the link below:
http://support.microsoft.com/kb/308909
We can also add a method to move rows within a DataTable, please refer to the link below:
http://www.codeproject.com/Tips/312545/A-method-to-move-rows-within-a-DataTable
Hope it’s useful for you.
Best Regards,
Michelle Ge
Feedback to us
Develop and promote your apps in Windows Store
girimalla
0 Points
2 Posts
Re: Selecting rows in DataTable based on Filter Criteria in C# with using OLEDB
Sep 03, 2013 04:46 AM|LINK