Many times, when you are returning results from a database, there will be nulls. Here’s how to handle it when it happens while using a DataReader:
While objDR.Read
sAuthor=objDR("Author")
sBorn=FixBirthDate(objDR("YearBorn"))
End While
DataBind
End Sub
Here’s the FixBirthDate Function:
Function fixBirthDate(sItem) as String if sItem is System.DBNull.Value Then fixBirthDate="<i><font Color='#FF0000'>No Date Specified</font></i>" else fixBirthDate="<b>" & sItem & "</b>" End If End function
Then, on the page, you can refer to the items like this:
<%# sAuthor%> – <%# sBorn%>
Here’s a complete Code Sample, showing this in a slightly varied way, but with the same general concept:
Handling Database Nulls with a DataReader