Assign: Conversion from type 'DBNull' to type 'Double' is not valid. If the Value is null I want to assign it as 0

suggest a method to resolve it,I Want to assign 0 value if the column is empty,So suggest a proper method to get it

1.Read your excel with read range workbook activity… Create a variable like dt

  1. Take for each row activity and pass dt as input to that

  2. Inside the loop take If activity

If condition give like this
String.IsNullOrEmpty(row(“YourColumnName”).ToString)
Then
Assign: row(“YourColumnName”) = “0”
End If

This way you can add 0 to null column

Out Of the for each loop you can use the write range workbook activity to write to excel

@Gopikrishna_S

Let me it’s working or not or you can share sample i will design work flow for you…!

@Gopikrishna_S

Hi @Gopikrishna_S

=> Use Read Range Workbook acitvity to read the excel and store the output in an datatable.
=> Use a “For Each Row in DataTable” activity to loop through each row in the DataTable.
=> Inside the loop, use an “If” activity to check if the specific column is empty in the current row.

If String.IsNullOrEmpty(CurrentRow("ColumnName").ToString) Then
    CurrentRow("ColumnName") = "0"
End If

Replace "ColumnName" with the name of the column you want to check.
=> After modifying the DataTable inside the loop, you can use the “Write Range” activity to write the updated DataTable back to the Excel or CSV file.

Hope it helps!!

If: Expression Activity type ‘VisualBasicValue`1’ requires compilation in order to run. Please ensure that the workflow has been compiled. getting this error

If: Expression Activity type ‘VisualBasicValue`1’ requires compilation in order to run. Please ensure that the workflow has been compiled. getting this

Make you to give the double quotes properly @Gopikrishna_S . Remove the double quotes and give it again. It will solve the error.

Regards

1 Like

@Gopikrishna_S

Please try this

requiredvalue = If(currentRow("ColumnName") is DBNull.Value,0,Cint(currentRow("ColumnName").ToString))

Or

currentRow("ColumnName") = If(currentRow("ColumnName") is DBNull.Value,0,Cint(currentRow("ColumnName").ToString))

Cheers

You can try like this

CurrentRow(“ColumnName”) =0

output :
image

@Gopikrishna_S

You can try this both ways
in column name i have given values but you can mention your column name

for reference you can see the output :-

image

let me know its working or not for you
@Gopikrishna_S

Hi @Gopikrishna_S

If you find solution for your query please mark it as solution to close the loop.

Happy Automation

Regards