>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.
insertCommand.Parameters.Add(String.Format("@PC{0}Amt", i), SqlDbType.Money).Value = (i-1 < splitAmounts.Count) ? splitAmounts[i-1] : 0 ;
:-)
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.