IIF shortern to one datarow .Net Is it possible to shorten the Isnull checking? 

It would be great to shorten this code and only have to put the datarow once. 

This code imports data details (usually there would be more .x = IIF.... statements)

 Public Class apPropertyFunctions

        Public Function GetProperty(ByVal sUPRN As String) As apProperty
            'Public Function GetProperty(ByVal sUPRN As String, ByVal sUCARN As String) As apProperty
            Try

                Dim vIP As String = HttpContext.Current.Request.ServerVariables("REMOTE_ADDR")
                Dim oDetails As New apProperty

                Dim sConnString As String = System.Web.Configuration.WebConfigurationManager.ConnectionStrings("SQL_DEMO").ConnectionString
                Dim dsNames As SqlDataSource

                dsNames = New SqlDataSource

                dsNames.ConnectionString = sConnString
                Dim sSQL As String
                sSQL = "spGetProperty"
                dsNames.SelectCommand = sSQL
                dsNames.SelectCommandType = SqlDataSourceCommandType.StoredProcedure
                dsNames.SelectParameters.Clear()
                dsNames.SelectParameters.Add("ID", ID)

                For Each datarow As Data.DataRowView In dsNames.Select(DataSourceSelectArguments.Empty)

                    With oDetails
                        .ID= datarow("ID").ToString    
     .BuildingNo = IIf(datarow("BuildingNo").Equals(DBNull.Value), "", datarow("BuildingNo").ToString)
                    End With

                    '  End If
                Next

                dsNames = Nothing

                Return oDetails

            Catch ex As Exception
                Return Nothing
            End Try

        End Function
Don't leave garbage laying around please, pick up after yourself.

'  End If


This doesn't have a purpose here, just get rid of it.



This isn't a good idea either

        Catch ex As Exception
            Return Nothing
        End Try


This was probably meant to close the connection, but there is a much better way to do that than to catch all exceptions and not report them.  Using Statements.



This is kind of smelly to me as well.

            Dim sSQL As String
            sSQL = "spGetProperty"
            dsNames.SelectCommand = sSQL


This simple Function doesn't need to be any more difficult than it has to be, you should do one of two things here.


Pass in the Stored Procedure Name as a string to the function
just set the SelectCommand to the name of the stored procedure like:

dsNames.SelectCommand = "spGetProperty"





It doesn't look like there is any reason whatsoever to call dsNames.SelectParameters.Clear() this object was created here and there is nothing in it yet, there should be no reason that you need to clear nothing.

Some other things that you don't need include

            Dim vIP As String = HttpContext.Current.Request.ServerVariables("REMOTE_ADDR")


And 

        'Public Function GetProperty(ByVal sUPRN As String, ByVal sUCARN As String) As apProperty




With all that I left in the Try/Catch statement because I didn't know exactly what you were needing it for, but this is what it would look like with all these changes.

Public Function GetProperty(ByVal sUPRN As String) As apProperty
    Try
        Dim oDetails As New apProperty
        Dim sConnString As String = System.Web.Configuration.WebConfigurationManager.ConnectionStrings("SQL_DEMO").ConnectionString

        Using dsNames As New SqlDataSource
            dsNames.ConnectionString = sConnString
            dsNames.SelectCommand = "spGetProperty"
            dsNames.SelectCommandType = SqlDataSourceCommandType.StoredProcedure
            dsNames.SelectParameters.Clear()
            dsNames.SelectParameters.Add("ID", ID)

            For Each datarow As Data.DataRowView In dsNames.Select(DataSourceSelectArguments.Empty)
                With oDetails
                    .ID = datarow("ID").ToString    
                    .BuildingNo = IIf(datarow("BuildingNo").Equals(DBNull.Value), "", datarow("BuildingNo").ToString)
                End With
            Next
        End Using
        Return oDetails
    Catch ex As Exception
        Return Nothing
    End Try
End Function