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:
00737105
Views:
25
Hi Cathi,

The following works but why won't the other?

Dim myDataRow As DataRow
Dim MyEmailBody1 As String
Dim MyEmailBody2 As String
Dim MyEmailBody3 As String
Dim MyEmailBody4 As String
Dim MyEmailBody5 As String
Dim MyEmailBody6 As String
Dim MyEmailBody7 As String
Dim MyEmailBody8 As String
Dim MyEmailBody9 As String
For Each myDataRow In NhdCreateReportOrders_Ds.Tables("CbBksfldNhdDailyOrders").Rows
If myDataRow("AccountId") Is DBNull.Value Then
MyEmailBody1 = ""
Else
MyEmailBody1 = myDataRow("AccountId") & " "
End If
If myDataRow("OrderNumber") Is DBNull.Value Then
MyEmailBody2 = ""
Else
MyEmailBody2 = myDataRow("OrderNumber") & " "
End If
If myDataRow("APN") Is DBNull.Value Then
MyEmailBody3 = ""
Else
MyEmailBody3 = myDataRow("APN") & " "
End If
If myDataRow("StreetNumber") Is DBNull.Value Then
MyEmailBody4 = ""
Else
MyEmailBody4 = myDataRow("StreetNumber") & " "
End If
If myDataRow("StreetDirection") Is DBNull.Value Then
MyEmailBody5 = ""
Else
MyEmailBody5 = myDataRow("StreetDirection") & " "
End If
If myDataRow("Street") Is DBNull.Value Then
MyEmailBody6 = ""
Else
MyEmailBody6 = myDataRow("Street") & " "
End If
If myDataRow("City") Is DBNull.Value Then
MyEmailBody7 = ""
Else
MyEmailBody7 = myDataRow("City") & " "
End If
If myDataRow("State") Is DBNull.Value Then
MyEmailBody8 = ""
Else
MyEmailBody8 = myDataRow("State") & " "
End If
If myDataRow("Zip") Is DBNull.Value Then
MyEmailBody9 = ""
Else
MyEmailBody9 = myDataRow("Zip") & " "
End If
MyEmailBody = MyEmailBody1 + MyEmailBody2 + MyEmailBody3 + MyEmailBody4 + MyEmailBody5 + MyEmailBody6 + MyEmailBody7 + MyEmailBody8 + MyEmailBody9 + ControlChars.CrLf

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