Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Iif(isdbnull correct syntax?
Message
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
00736677
Message ID:
00737520
Views:
25
Hi Cathi,

Thanks for your help.

It works in VFP. Is this a bug in VB .net? Should it return the result of A expression if conditon is false and B expression if condition is true?

Does it evaluate the expressions and return the result of the evaluation of the condition?

Thanks
Roland

==========================================================================

>Hi Roland,
>
>I found your problem. You are using the Trim function in your IIf statement. What is happening, is .NET is evaluating the false expression, even though the IIf statement is true. It will return the true result but if the false portion causes an error, the error will be thrown. When you used the Trim function, the expression inside of it returned DBNull istead of a string. This caused the expection to be thrown, even though this portion of the IIf statement was not being returned. If you remove the Trim function, then your code should execute properly.
>
>>Hi Cathi
>>
>>I tried the Northwind and it works. I tried subsituted my table and it did not work.
>>
>>The only difference I noticed in the Northwind Table, Field REGION and My Field APN is that REGION is a nvarchar and mine APN is defined as varchar. Would that make a difference?
>>
>>Thanks
>>Roland
>>
>>===========================================================================
>>
>>
>>>Hi Roland,
>>>
>>>Your syntax should be okay from what I can tell. Here is a sample program that tests your syntax against the SQL Server Northwind database. This doesn't generate any errors for me. Try this code. If no errors then the problem is somewhere else in your data.
>>>
>>>
>>>Dim oConnStr As String = "data source=localhost;initial catalog=Northwind;user id=sa;password="
>>>Dim oConn As New SqlConnection()
>>>oConn.ConnectionString = oConnStr
>>>oConn.Open()
>>>
>>>' Create a Command object with select statement
>>>Dim strSelect As [String] = "SELECT * FROM CUSTOMERS where customerid like 'C%'"
>>>Dim oSelectCommand As New SqlCommand(strSelect, oConn)
>>>
>>>' Create a DataAdapter
>>>Dim da As New SqlDataAdapter()
>>>da.SelectCommand = oSelectCommand
>>>
>>>' Create a DataSet
>>>Dim ds As New DataSet()
>>>
>>>' Fill the DataSet with table information
>>>da.Fill(ds, "CUSTOMERS")
>>>
>>>Dim dr As DataRow
>>>For Each dr In ds.Tables("CUSTOMERS").Rows()
>>>    MessageBox.Show(IIf(IsDBNull(dr("Region")), "Value is Null", dr("Region")))
>>>Next
>>>
>>>oConn.Close()
>>>
>>>
>>>>Hi,
>>>>
>>>>I encountered the following error message with the code below the error message.
>>>>
>>>>An unhandled exception of type 'System.InvalidCastException' occurred in microsoft.visualbasic.dll
>>>>Additional information: Cast from type 'DBNull' to type 'String' is not valid.
>>>>
>>>>MyEmailBody = myDataRow("AccountId") & " " & _
>>>>myDataRow("OrderNumber") & " " & _
>>>>IIf(IsDBNull(myDataRow("APN")), "", Trim(myDataRow("APN"))) & " " & _
>>>>IIf(IsDBNull(myDataRow("StreetNumber")), "", Trim(myDataRow("StreetNumber")))
>>>>
>>>>What is the proper code to cancanate the string?
>>>>
>>>>Any help would be greatly appreciated.
>>>>
>>>>
>>>>Thanks
>>>>Roland
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform