Attached is my program, where I want the data of 3 columns on the basis of “if condition”, however after execution getting all the data of the input datatable with the data according to the “If condition” in the output.xls file.
Using this method:
“inputDT.DefaultView.ToTable(true,“Name”,“Subjects”,“Marks”)”
I am not sure what’s your condition requirement but you can use Select command. e.g. DataTableObj.Select(“col1=‘value1’”) it will return you the DataRow object which you can just iterate through general for each loop and do whatever you want.
The above expression is working fine if you want to fetch selected rows from the input excel file.
My issue is that…I want to keep only the selected header column from my input excel file and data based on only my if condition. My program was working if i use the method DefaultView.totable(true, “column1”, “column2”). It returns the selected columns but all the records of input excel file as well and i want only those records which satisfy the if condition only. If you run my above program you see that the output.xlsx file is generated with all the records that are in input excel and also records which comes from the if condition.
Refer My Screenshots of input and output fie…I want only 2 records in the output file not all the records.
I also used “inputDT.clone” method, it works but all columns are returned and i want selected columns only.
@lakshman
This expression is giving error as “the source contains no data rows”. However i found one alternative of doing this is by using the build data table concept.
Define all the columns that you want under build data table and make it clone of that to output datatable and using add data rows read the values.