[dba-VB] VB.Net combo

John Colby jwcolby at ColbyConsulting.com
Tue Jan 10 18:12:12 CST 2006


I'm trying to set up a combo in VB programmatically.  The following is what
I am using:

    Function LoadCboService()
        Dim strCnn As String = My.Settings.C2DbConquestConnectionString
        Dim cnn As New SqlConnection(strCnn)
        cnn.Open()
        Dim strSQLService As String = "SELECT * FROM tlkpService"
        Dim cmd As New SqlCommand(strSQLService, cnn)
        Dim adpt As New SqlDataAdapter(cmd)

        Dim Ds As DataSet
        Ds = New DataSet("cboService")
        adpt.Fill(Ds, "cboService")
        cboService.DataSource = Ds.Tables("cboService")
        cboService.DisplayMember =
Ds.Tables("cboService").Columns("RA_Rank").ToString
        cboService.ValueMember =
Ds.Tables("cboService").Columns("RA_ID").ToString
        Return True
    End Function

The function runs to 

        cboService.DisplayMember =
Ds.Tables("cboService").Columns("RA_Rank").ToString

And fails with:  "null reference exception was unhandled"

I am trying to populate a combo box with two columns of a table, the PK
column, and the "display" or text value column.

What am I doing wrong?

John W. Colby
www.ColbyConsulting.com 





More information about the dba-VB mailing list