Re: IIF Function
- From: "Chris Botha" <chris_s_botha@xxxxxxxxxxxxx>
- Date: Wed, 7 Sep 2005 09:27:34 -0400
I've been doing this since the days of VB6 and ADO, no problems yet.
Thanks for the comments though.
"Kevin Spencer" <kevin@xxxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:ecsfaT6sFHA.3528@xxxxxxxxxxxxxxxxxxxxxxx
>> 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?
>>>
>>
>>
>
>
.
- References:
- IIF Function
- From: Sparky Arbuckle
- Re: IIF Function
- From: Chris Botha
- Re: IIF Function
- From: Kevin Spencer
- IIF Function
- Prev by Date: Re: Bad Data Error
- Next by Date: RE: Lost Cookie during Authentication
- Previous by thread: Re: IIF Function
- Next by thread: Re: IIF Function
- Index(es):
Relevant Pages
|