Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

Converting dataset to list incorrect type

$
0
0

I am trying to convert a dataset into a list but for some reason its failing when a datarow column is null when going in a type of double.. It  appears to be this line that is giving me trouble any ideas of what I could to solve it.

_supplier.supplier_price = (double)dr["SupplierPrice"];

public List<SuppliersDetails> copyDstoSupplierDetails(DataSet ds)
 {
      int table = Convert.ToInt32(ds.Tables.Count);// count the number of table in dataset
      for (int i = 0; i < table; i++)// set the table value in list one by one
          {
                foreach (DataRow dr in ds.Tables[i].Rows)
                {
                    SuppliersDetails _supplier = new SuppliersDetails();
                    _supplier.code = (string)dr["Product Code"];
                    _supplier.long_description = (string)dr["Long Description"];
                     _supplier.supplier_price = (double)dr["SupplierPrice"];


                    _supplierDetails.Add(_supplier);
                }
            }
            return _supplierDetails;
 }

My generic list collection is very simple

 public class SuppliersDetails
    {
        public string code { get; set; }
        public string name { get; set; }
        public string warehouse { get; set; }
        public string long_description { get; set; }
        public string unit_code { get; set; }
        public double sterling { get; set; }
        public double nsterling { get; set; }


        public double neuro { get;set;}
        public double euro { get; set; }
        public double supplier_price { get; set; }
        public double nsupplier_price { get; set; }

        public string description { get; set; }

        public SuppliersDetails()
        {


        }
        public  SuppliersDetails (string Code,string Productname,string LongDescription,string UnitCode,double Sterling,double NSterling,double Euro,double Neuro,double Supplier_price ,double NSupplier_price)
        {

            this.code = code;
            this.name = Productname;
            this.long_description = LongDescription;
            this.unit_code = UnitCode;
            this.sterling = Sterling;
            this.nsterling = NSterling;
            this.neuro = Neuro;
            this.euro = Euro;
            this.supplier_price = Supplier_price;
            this.nsupplier_price = NSupplier_price;

        }


Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>