I have problem with getting a count of the number of rows in a data table, the Data Table is created from a Data Scraping.
Even if the Data Table is empty (I checked it for sure by export to csv file), DataTable.Rows.Count.ToString shows 1 row.
Also if Data Table has one row, counter still shows 1.
I tried with indexes, DataTable.Rows.IndexOf(row).ToString, with empty list Index = 0, with one row Index = 0, with two rows there are three indexes 0, 1 and 2.
Is there another way to count DataTable rows ? (I would like to avoid the solution of writing to csv file and then counting number of rows from it )
create a variable counter
initialize the counter in 0 before the for each
inside the for each increment counter with assign activity counter = counter+1
Even if the DataTable has no values and returns nothing to csv file, the for each loop starts. I put DataTable.Rows.IndexOf(row).ToString inside For each and with empty list I’ve got index =0 and with one row list index also equals 0. For number of rows greater than 1 indexes are OK, from 0 to DataTable.Rows.Count for example two rows: 0,1,2. Three rows: 0,1,2,3 etc. I’ve got problem only with identify if there is one or none rows in DataTable.Thanks for the answer but It will not works.
OutputDataTable returns something, if I put OutputDataTable result into string and MessageBox, I see nothing but the len(string) = 4. String.IsNullOrEmpty(string) and IsNothing(string) does not work. Now I can check the len statement of OutputDataTable, of course if it will be always working ? Thanks
Output data table returns following:
If data table empty (returns a column(as default header) and count 1)
If data table has one row (returns first item with count 1)
Have you tried deleting empty/Blank datarows and then trying to count the number of rows? After the removal of empty rows, you should get the row count correct.
Hi Amrita, how to identify and delete empty/Blank rows ?
In conclusion with empty list:
DataTable.Rows.Count = 1
OutputDataTable returns len(string) = 4
String.IsNullOrEmpty(string) and IsNothing(string) does not work
In For each row loop, loop starts but row.Item(0).ToString = IndexOutOfRange Error, the same error with row.Item(1).ToString
export DataTable to csv gives empty file (working with list of one row, DataTable.Rows.Count = 1 and csv have two rows, one with column names and datarow)
Thanks anyway, but I have found that the Filter Data Table activity works!
I have successfully tested in where my dt should be blank and was returning a count of 1 (it now returns 0, as expected); I also tested it where I had rows with data separated by blank rows.
Have you used the build data table activity to initialise the table? If so, that comes with one default row as standard. Go to the activity click on datatable and delete all rows under the headers using the cross on the left hand side.
I just tried this with mine and it returned a DT size of 1 first, then a size of 0 when I deleted the default row in the activity