Concatenating Multiple NonNull Columns into Combobox Text Property

daniness

Well-known member
Joined
Feb 12, 2010
Messages
49
Programming Experience
Beginner
Hello All,

I would greatly appreciate your assistance with this issue. I'm trying to concatenate nonnull multiple columns from a database into the text property of a combobox. Right now, I'm receiving an "IndexOutOfRangeException was unhandled name, address1, address2". The line in red is where the error is occurring. Here is my code for this section:

VB.NET:
Dim drFreight As SqlDataReader = cmdCorrespFreight.ExecuteReader 
 
        While drFreight.Read() 
            'If "address3" <> "" Then 
            If IsDBNull(drFreight("address3")) Then 
                cboFreight.Text = drFreight("name" & ", " & "address1" & ", " & "address2" & ", " & "address3") 
                'If "address4" <> "" Then 
                If IsDBNull(drFreight("address4")) Then 
                    cboFreight.Text = drFreight("name" & ", " & "address1" & ", " & "address2" & ", " & "address3" & ", " & "address4") 
                End If 
            Else 
                [COLOR="Red"]cboFreight.Text = drFreight("name" & ", " & "address1" & ", " & "address2") [/COLOR]            
            End If 
 
        End While 
        drFreight.Close()
 
VB.NET:
[COLOR="Red"]cboFreight.Text = drFreight("name" & ", " & "address1" & ", " & "address2") [/COLOR]

Shouldnt it be :-

VB.NET:
cboFreight.Text = drFreight("name").toString & ", " & drFreight("address1").toString & ", " & drFreight("address2").toString

or even :-

VB.NET:
cboFreight.Text = string.format ("{0}, {1}, {2}", drFreight("name"), drFreight("address1"), drFreight("address2"))
 
Back
Top