Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
C# nullable type blues
Message
De
27/11/2015 12:05:09
 
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
C# 5.0
OS:
Windows 10
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Desktop
Divers
Thread ID:
01627989
Message ID:
01627992
Vues:
49
You need to check turnoverTransactiions.Comput(....).HasValue. If it does, then you can do the cast.


>
>        public static void addTurnover(D010Invoices.Invoice invoice)
>        {        
>            var turnoverTransactions = D010.loadTurnover(invoice.document);
>            decimal total = 0;
>            decimal? totalPaid = 0;
>            if (turnoverTransactions.Rows.Count > 0)
>            {
>                total = (decimal)turnoverTransactions.Compute("sum(amount)", "true");
>                totalPaid = (decimal?)turnoverTransactions.Compute("sum(amount)", "document like 'AP*'");
>                if (totalPaid==null)
>                {
>                    totalPaid = 0;
>                }
>
>            }
>
>
>.... so why do I get a casting error in the totalPaid line when the document does not start with "AP"?
>
>*** UPDATE ***
>Because DataTable.Compute() returns DBNull.Value and not null....
Craig Berntson
MCSD, Microsoft .Net MVP, Grape City Community Influencer
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform