DataTable conversion to String

Hello,
I am trying to calculate the difference between the values in two or more columns (in 2 sheets). I pulled data from excel files in the database and for calculating values in 2 columns I am using the following formula:

(Convert.ToDouble(dt_SLB_Page1.Rows(int_counter_row).Item(0)) - Convert.ToDouble(dt_FI_Page1.Rows(int_counter_row).Item(0))).ToString

The formula works fine in cases when some values are assigned in each column, But whenever there is value in missing, the column with results stays empty. Here is an example:

Sheet 1


Sheet 2

And as a result:

As I said, when there are some values in both colums I am comparing, it works fine.

Regards,
S.

Hi @sspi1153

you can use the if condition to check whether the column value is empty or not before proceeding with the comparison. apply the formulae if both columns are not null.

Ex: dt_SLB_Page1.Rows(int_counter_row).Item(0).toString <>“” and Convert.ToDouble(dt_FI_Page1.Rows(int_counter_row).Item(0).toString <> “”

In other case where the column is null you keep the column data which is not null in the comparison.

Hope this solves your problem. Happy Learning…

1 Like

Thanks,
I got it. But there is additional question;)

The cells those are not compared (have value only in one column) are saved as text entries in Excel. How can I prevet this - same the as numbers?
Elese formula is: convert.ToString(dt_SLB_Page1.Rows(int_counter_row).Item(0).toString +dt_FI_Page1.Rows(int_counter_row).Item(0).toString)

image
image

Thanks and Regards,
S.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.