Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to prevent possible error in this code?
Message
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Titre:
How to prevent possible error in this code?
Versions des environnements
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01599006
Message ID:
01599006
Vues:
47
Hi everybody,

I am writing this code:
 for (Int16 i = 1; i <= 6; i++ )
                {
                    insertCommand.Parameters.Add(String.Format("@pr_ctr_{0}", i), SqlDbType.Int).Value = drItem.Field<Int32>(String.Format("pr_ctr_{0}", i));

                    insertCommand.Parameters.Add(String.Format("@PC{0}Amt", i), SqlDbType.Money).Value =  splitAmounts[i-1] ;
                }
splitAmounts variable defined as
List<Decimal>
I want to prevent possibility of that list having less than 6 elements, so in this case I would assign 0 to my parameter. Is there a way to do it in one line (change the last line) or I should add an extra if to check
i-1 < splitAmounts.Count
?

I guess I can use IIF C# analogue here.
If it's not broken, fix it until it is.


My Blog
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform