Andy5
(Andy)
July 3, 2023, 5:06pm
1
Hi All,
How to delete all rows except the Header from the data table?
PatientName
TIMESTAMP
Account Number
Facility
Payer
ABC
1
123
x
Z
CDC
1
321
x
Z
ZZZ
1
456
x
Z
kkk
1
987
x
Z
MMM
1
897
x
Z
I want to keep only the header in
Thanks in advance.
Andy
@Andy5
if clearing means keep structure and remove rows - then:
yourDT = yourDT.Clone
if clearing means reset it to null
yourDT = nothing
if clearing means reset it to initialized form, that it can bused for further work
yourDT = new DataTable()
Post updated.
@Andy5
Use Clear Data Table activity and pass Datatable variable in it.
Thanks
1 Like
@Andy5
You want to keep only headers then
Use assign activity.
Left side
ā YourDT
Right side
ā YourDT.Clone
Andy5
(Andy)
July 3, 2023, 5:37pm
5
i need to keep only Header if i used āUse assign activity.
Left side
ā YourDT
Right side
ā YourDT.Cloneā then it will clone all data?
Thanks in advance.
Andy
1 Like
Andy5
(Andy)
July 3, 2023, 5:37pm
6
it will clear all data with Headersā¦
Thanks in advance.
Andy
1 Like
@Andy5
Clone operation only cloning header
@Andy5
Sureā¦and donāt forget to mark solution if your problem solve.
Hi @Andy5
You can simply retain the header like this:
ā Read the excel with with āAdd Headersā option disabled.
ā Use this expression in the Assign activity:
yourDt = yourDt.AsEnumerable.Take(1).CopyToDataTable
Now yourDt will only contain the header details.
Hope this helps,
Best Regards.
Venkat4
(Srikanth BV)
July 3, 2023, 6:30pm
12
Hi @Andy5 ,
you can use clear data table activity to delete all the rows except the headers from the data table.
Cheers
@Andy5
It will not clear the headersā¦It will only clear the rows data.
Thanks,
Pratik
vrdabberu
(Varunraj Dabberu)
July 4, 2023, 6:11am
14
Hi @Andy5
Read the excel by using read range activity and store the data in a variable.
Pass the variable into clear data table activity and run the code so that all the rows get deleted from the data table except the header.
Hope it helps !!
Regards
Hi @Andy5 ,
If you wish to delete all rows except header use the activity clear datatable .
Please Refer the image below
1 Like
Hello this is Gulshan Negi
Well, to delete all rows except the Header from the datatable.
dataTable.Rows.Cast().Where(row => row != dataTable.Rows[0]).ToList().ForEach(row => row.Delete());
dataTable.AcceptChanges();
I hope you are clear now.
Thanks
system
(system)
Closed
July 7, 2023, 4:29pm
17
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.