Answered by:
skip data row if the row content is similar to column name

Question
-
User-73514677 posted
Hi
How to skip datarow in the dataTable ( using c# ) , if the contents of the datarow are similar to the column name?
Thanks
Friday, April 3, 2020 12:31 PM
Answers
-
User475983607 posted
Clearly you made no effort and have not run the code! Loop over the rows and check the items.
Another option is using LINQ to filter the DataTable.
https://stackoverflow.com/questions/19449449/how-i-can-filter-a-datatable-with-linq-to-datatable
The .NET DataTable also has a Select() method which is yet another filter option.
https://docs.microsoft.com/en-us/dotnet/api/system.data.datatable.select?view=netframework-4.8
I assume skip means you do not want to move the record to another table or collection. Unfortunately you're requirement is vague and you have not provide enough code to figure out the intent.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, April 3, 2020 1:13 PM
All replies
-
User475983607 posted
How to skip datarow in the dataTable ( using c# ) , if the contents of the datarow are similar to the column name?What does "similar" mean? Please share you code.
Friday, April 3, 2020 12:49 PM -
User-73514677 posted
Hi.
I mean, if the column name is - Name Address
datarow[i] is also - Name Addresss
then skip the row
Thanks
Friday, April 3, 2020 12:52 PM -
User475983607 posted
venkatzeus
Hi.
I mean, if the column name is - Name Address
datarow[i] is also - Name Addresss
then skip the row
Thanks
You need to write an "if" statement or query and filter? Please share your code.
Friday, April 3, 2020 12:58 PM -
User-73514677 posted
Hi.
I tried the below:
foreach(DataColumn dcol in DtTable.Column) { foreach(DataRow drow in DtTable.Rows ) { if(dcol.ToString() == drow.ToString() { // column name and datarow are same.. skip this row } } }
Friday, April 3, 2020 1:02 PM -
User475983607 posted
Clearly you made no effort and have not run the code! Loop over the rows and check the items.
Another option is using LINQ to filter the DataTable.
https://stackoverflow.com/questions/19449449/how-i-can-filter-a-datatable-with-linq-to-datatable
The .NET DataTable also has a Select() method which is yet another filter option.
https://docs.microsoft.com/en-us/dotnet/api/system.data.datatable.select?view=netframework-4.8
I assume skip means you do not want to move the record to another table or collection. Unfortunately you're requirement is vague and you have not provide enough code to figure out the intent.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, April 3, 2020 1:13 PM -
User-73514677 posted
Hi.
In other words, the excel has the first row of data, which is the column header name. I have tried setting HDR = Yes, but this has not worked.
In the datatable , i can see the header name as F2 F3 F4...
The actual column header is coming as the first row
Thanks
Friday, April 3, 2020 1:28 PM -
User475983607 posted
venkatzeus
In other words, the excel has the first row of data, which is the column header name. I have tried setting HDR = Yes, but this has not worked.This is the first you mentioned Excel in this thread. You sill have not provided a single line of code or source file that illustrate the issue; not event the code that populates the DataTable.
Please read the links in my previous thread. Come up with a design and write some code. If you still have a problem after doing basic development work, share your code.
Friday, April 3, 2020 3:04 PM