mercredi 6 mai 2015

Converting double to float C# WPF

I need to display information in a datagrid from my tblSysproStock table. The table has columns with float values in them and in my application I need to convert the double value to a float value

My coding where I want to fill my datagrid:

private void FillSysproDataGrid()
{
    using (DataClassesDataContext DC = new DataClassesDataContext())
    {
        dgSysproStock.ItemsSource = DC.tblSysproStocks.Where<tblSysproStock>(c => c.StockID != null)
            .Select<tblSysproStock, SSData>(m => new SSData()
            {
                SID = m.StockID,
                SCode = m.StockCode,
                SDescription = m.StockDescription,
                SConvFactAltUom = (float)m.ConvFactAltUom,
                SConvMulDiv = m.ConvMulDiv,
                SConvFactOthUom = (float)m.ConvFactOthUom,
                SMulDiv = m.MulDiv,
                SMass = (float)m.Mass,
                SUpdatedSupplier = m.UpdatedSupplier,
                SCycleCount = (float)m.CycleCount,
                SProductClass = (float)m.ProductClass,
                SUnitCost = (float)m.UnitCost,
                SSegal = m.Segal,
                SWareHouse = m.Warehouse,
                SMinimumStock = (float)m.MinimumStock,
                SMaximumStock = (float)m.MaximumStock,
                SStockForNow = (float)m.StockForNow,
                SStockCount = m.StockCount,
                SValue = (float)m.Value,
            });
    }
}

I am equaling my values from my table to my SSData class:

public struct SSData
{
    public string _ss;

    public int SID { get; set; }
    public string SCode { get; set; }
    public string SDescription { get; set; }
    public float SConvFactAltUom { get; set; }
    public string SConvMulDiv { get; set; }
    public float SConvFactOthUom { get; set; }
    public string SMulDiv { get; set; }
    public float SMass { get; set; }
    public string SUpdatedSupplier { get; set; }
    public float SCycleCount { get; set; }
    public float SProductClass { get; set; }
    public float SUnitCost { get; set; }
    public string SSegal { get; set; }
    public string SWareHouse { get; set; }
    public float SMinimumStock { get; set; }
    public float SMaximumStock { get; set; }
    public float SStockForNow { get; set; }
    public string SStockCount { get; set; }
    public float SValue { get; set; }
}

Now the error that I am getting is -

The null value cannot be assigned to a member with type System.Single which is a non-nullable value type. When I run my application.

I think that it's the conversion that is the problem? Anyone with any advice or solutions would be great! Thank you.

Aucun commentaire:

Enregistrer un commentaire