Hi,
You have may have to create a function to return reading of your data row (dr) an empty string in case your data row (dr) contents null.
Try to change your code for loop as sample below:
For Each dr As DataRow In dt.Rows
Items.SetValue(EmptyIfNull(dr("CourseCode")) & " | " & EmptyIfNull(dr("CourseName")), i)
i += 1
Next
and here is the function:
Public Shared Function EmptyIfNull(ByVal p As Object) As String
Dim retValue As String = String.Empty
Try
If Not (p.Equals(DBNull.Value)) Then
'retValue = DirectCast(p, String)
retValue = CType(p, String)
End If
Catch ex As Exception
retValue = String.Empty
End Try
Return retValue
End Function
You may also use such query as example: ( This is the recomended solution...)
Select Distinct case when CourseName = null then '' else CourseName end,
case when CourseCode = null then '' else CourseCode end from Course
Where DisciplineID=@DisciplineID And ([CourseCode] like @prefixText or [CourseName] like @prefixText)
Hope this could help...
Regards,