2.0 beta - Import Products Excel - Object cannot be cast from DBNull to other types

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
12 years ago
I've seen several posts about this for prior versions.  May I suggest we fix it...

ImportManager.cs
        public virtual void ImportProductsFromXls(string filePath)

change
                foreach (DataRow dr in dt.Rows())

to
                foreach (DataRow dr in dt.Select("name is not NULL"))


Similarly for another common import issue  - 'Products$' is not a valid name.
Could we also trap that and then look for Sheet1$ ?
12 years ago
Hi,

This is an issue I've been struggling with for a while.

I'm currently looking in ImportManager.cs and I don't actually see that line.

In the function "ImportProductsFromXls" I see the:

foreach (DataRow dr in dt.Rows)

but not:

foreach (DataRow dr in dt.Rows())


I'm using nop 1.9 -  I see you're using 2.0 beta (will look further into 1.9)

thanks

David
12 years ago
Yes, my orig post was based on 2.0 beta.
When 2.0 was released, this is the way the team fixed it:


                foreach (DataRow dr in dt.Rows)
                {
                    if (dr.ItemArray.All(i => string.IsNullOrEmpty(i.ToString())))
                        continue;


(i.e. if all the cells in the row are empty, then skip to next record)
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.