c# - Excel Import Data Parse Error Of Internationaly Formatted Numbers -
i'm importing excel file , want add values database. in database there type decimal(18, 5) , want add value 0.00204 column in database. variable in model class of type decimal , i'm trying code:
convert.todecimal(items[7]);
but error input if not correct format. items of type object[]. how parse value decimal?
all others work fine:
product.packsize = convert.toint32(items[3]); product.leadtime = convert.tostring(items[4]); product.generalaccessorycategoryid = convert.toint32(items[5]); product.company = convert.tostring(items[6]); product.weight = convert.todecimal(items[7]);
check possible error conditions may exist @ stage once safe, extract string:
decimal result; if ((items!= null) && (items.any()) && (items[7] != null) && (decimal.tryparse(items[7].tostring(), out result)) product.weight = result;
after couple of comments , investigation, believe items[7] has characters convert not expecting. have updated answer above.
decimal result; decimal.tryparse("0a00204", out result); // returns false
Comments
Post a Comment