Hi All,
I have following requirement. I tried different options like Filter record, Filter record with Select, Filter Record in Linq. but I don’t get it. All the data is in one sheet.
(1) remove records from Status column where Status is Receipt and State
(2) remove records from “Payment” column where Payment is Check and Status is Void or Stop Payment. Eg:
Payment Status
Check Void
Stop Payment
(3) remove records from “Plan” column where value is 10 or 10A or 10B
in your excel sheet may be your data have white spaces or not having specified format
this also become reason for not working may be you can try with macros or VBA script that will work. go to your excel and filter by manually by record macros and use it
DT.AsEnumerable().Where(Function(row) Not(row("PAYMENT TYPE").ToString.Contains("Check")) AndAlso
Not(row("STATUS").ToString.trim.Contains("Void") Or row("STATUS").ToString.trim.Contains("Stop Payment") Or row("STATUS").ToString.trim.Contains("Check Void") Or row("STATUS").ToString.trim.Contains("10") Or row("STATUS").ToString.trim.Contains("State"))).CopyToDatatable()
Thank you Soooooooo much. I got it. But when I run the query it removes CHECK-RH also from the column. So i changed to = instead of contains. But now it is deleting records of CHECK-RH also.
DT.AsEnumerable().Where(Function(row) Not(row(“PAYMENT TYPE”).ToString = (“Check”)) AndAlso
Not(row(“STATUS”).ToString.trim.Contains(“Void”) Or row(“STATUS”).ToString.trim.Contains(“Stop Payment”) Or row(“STATUS”).ToString.trim.Contains(“Check Void”) Or row(“STATUS”).ToString.trim.Contains(“10”) Or row(“STATUS”).ToString.trim.Contains(“State”))).CopyToDatatable()
SELECT * FROM [Sheet1$] WHERE ([Status]<>'Receipt' AND WHERE [Status]<>'Receipt') AND (NOT([Payment]='Check' AND [Status]='Void') OR NOT([Payment]='Stop' AND [Status]='Payment')) AND ([Plan]<>'10' OR [Plan]<>'10'A OR [Plan]<>'10B')
you can test , change ,correct the query string, I am not sure the string i have given will give correct results
inorder to test the SQL query in normal easier way, try these :
Open a new DB file using MS access
Add a new data source(External data) , and navigate to from excel file and pick your input file
click “Create” tab->“Query Design”
right click on the new tab and click SQL View
Now you can type in any SQL query and run that using “Design”->“Run” button in the ribbon