Re: IIF Function
- From: "Kevin Spencer" <kevin@xxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 7 Sep 2005 08:08:24 -0400
> Dim intADCN As Integer = "0" &
> ds1.Tables("DataTable").Rows(0)("RevNumber")
Turning Option Strict Off is extremely bad practice, and the above code is a
horrible example of why. You're treating BOTH a string and possibly Nothing
as an Integer. You're also occasionally concatenating Nothing to a String.
This sort of coding can lead to all kinds of debugging headaches, as well as
not throwing exceptions that should be thrown, thus enabling your app to
pass the smell test in testing, and fail behind your back in production.
--
HTH,
Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.
"Chris Botha" <chris_s_botha@xxxxxxxxxxxxx> wrote in message
news:eHnlOPzsFHA.2076@xxxxxxxxxxxxxxxxxxxxxxx
> Taken from your example, this will return 0 if the value is Null, else the
> value:
> Dim intADCN As Integer = "0" &
> ds1.Tables("DataTable").Rows(0)("RevNumber")
>
>
> "Sparky Arbuckle" <twa@xxxxxxxxxxxxxx> wrote in message
> news:1126044243.445419.130500@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
>>I am using the IIF function in my application to create an instance and
>> value of a field if it doesn't exist in the query. I am using a
>> datagrid to display 4-5 items at a time and if one of the items doesn't
>> have a revision listed in tblRevisions then the whole page errors out.
>> I am using the following to try and fix the problem:
>>
>> Dim intADCN As Integer =
>> IIf(ds1.Tables("DataTable").Rows(0)("RevNumber") Is Nothing, 0,
>> ds.Tables("DataTable").Rows(0)("RevNumber"))
>>
>> I am getting an error: Cast from type 'DBNull' to type 'Integer' is not
>> valid. It seems as though instead of creating the instance and value of
>> 0, it is simply creating the instance of there being an a row there and
>> the value is null.
>>
>> Am I missing something or does anyone have any suggestions?
>>
>
>
.
- Follow-Ups:
- Re: IIF Function
- From: Chris Botha
- Re: IIF Function
- References:
- IIF Function
- From: Sparky Arbuckle
- Re: IIF Function
- From: Chris Botha
- IIF Function
- Prev by Date: Re: Downloading files
- Next by Date: Re: Absolute Beginner
- Previous by thread: Re: IIF Function
- Next by thread: Re: IIF Function
- Index(es):
Relevant Pages
|