Conversion from type DB null to type integer is not valid

I am trying to read data from excel sheet 1, writing that into my website portal
prices will be displayed on screen. I am scrapping that data into excel sheet 2
then i am doing a comparison between column 2 and column 3(data result scrapped from portal) entering data in 4 column as value matched or not.
After this operation i want to read new row from sheet 1( customer name and ship to.) repeat same process.
but after reading the first row in excel , scrapping the result and writing the output in column 4 , i am getting this error.

It seems there are null values which you are trying to convert to int. Use below method instead of .ToInt32

Convert.ToInt32()

I have tried this string.IsNullOrEmpty(row(0).ToString)=string.IsNullOrEmpty(row(1).ToString)
Its writing data in 4th column in excel for value not matched more than 180 times , while i am doing comparison only for 4 rows.
After that i got exception: Exception from HResult: 0*800AC472

I have also tried below statement:
cstr(cint(row(0))).ToString = cstr(cint(row(1))).ToString

Still not working.

Hi @divi2002,

Convert.ToInt32(Convert.tostring(Row(0)))

Try below code

cint(cstr(row(0)))= cint(cstr(row(1)))

Regards, Arivu :slight_smile:

Try,
Convert.toInt32(Convert.ToString(row(0)))=Convert.toInt32(Convert.ToString(row(1)))

or use IsDBNull method to check.

cint(cstr(row(0)))= cint(cstr(row(1)))
This is not working.Same error is still coming.
Conversion from type DBNull to String is not valid.

I cant add any attachments, unable to upload my xlsx file.