Getting error "If: Conversion from string "" to type 'Integer' is not valid."

Hi all,

I’m trying to give a condition in which I am checking if the datatable row is 0 or empty in an excel.
But I’m getting the error If: Conversion from string “” to type ‘Integer’ is not valid. as in below picture.

The condition I have given is:

cint(DT_Product.Rows(0)(“Actual”).ToString)= 0 or DT_Product.Rows(0)(“Actual”).ToString = “”.

Kindly please help.
Thanking you.

Try this @Yugal_Raju

String.IsNullorEmpty(DT_Product.Rows(0)(0).Tostring) Or CInt(DT_Product.Rows(0)(“Actual”).ToString).Tostring= 0 or DT_Product.Rows(0)(“Actual”).ToString = “”


value is blank so the CInt fails
give a try at following
isNothing(DT_Product.Rows(0)(“Actual”) OrElse String.IsNullOrEmpty(DT_Product.Rows(0)(“Actual”).ToString.Trim) OrElse cint(DT_Product.Rows(0)(“Actual”).ToString)= 0

Hi @Yugal_Raju
please try this one
dt Is Nothing OrElse Dt.Rows.Count = 0

example of usage :


Try this


to find Datatable empty

Here Rows(0)(0) indicates the DataTable 1st row of 1st column

That’s because if the value is empty, you’re trying to convert an empty value to int.

What you should do is use the “or else” operator.

DT_Product.Rows(0)(“Actual”).ToString = “” ORELSE cint(DT_Product.Rows(0)(“Actual”).ToString)= 0

What this does is looks at the first part and if it’s true it doesn’t bother even processing the second one, so the conversion to INT won’t be tried on an empty string. If the first is false, meaning the string is not empty, only then is the second expression processed.

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