Click here to Skip to main content
13,403,621 members (50,283 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I'm trying to populate a toolbar combobox with values from two fields in a database table. The table contains the following data:

1 Oracle Database
2 Microsoft SQL Server
4 Intrabase/Firebird
5 OleDB(ADO)
6 SQLite

I'm trying to populate the combobox from the Form_Load event.
Private Sub Form1_Load(ByVal sender As System.Object, _
                           ByVal e As System.EventArgs) _
                           Handles MyBase.Load
        Dim cn As New OleDbConnection
        Dim cm As OleDbCommand
        Dim da As New OleDbDataAdapter
        Dim strCnn As String
        Dim ds As New DataSet
        Dim strSQL As String
        strSQL = "SELECT * FROM tblDbTypes;"
        'Function to build Connection string
        strCnn = CnnCtrlDB(strAppPath & "\CtrlDB.ACCDB")
        cn = New OleDbConnection(strCnn)
            'Function to check db connection status
            Dim bCnn As Boolean = DBConnectionStatus(strCnn)
            If bCnn Then
                cm = New OleDbCommand(strSQL, cn)
                da.SelectCommand = cm
            End If
            'This SHOULD set the combobox index to 
            'number in the DBID field in the DB - IT DON'T
            tsCboDBTypes.ComboBox.ValueMember = "DBID"
            'This sets the combobox's DisplayMember to the 
            'value contained in the Db_Type field
            tsCboDBTypes.ComboBox.DisplayMember = "Db_Type"
            'Binds the combobox to the DataSet
            tsCboDBTypes.ComboBox.DataSource = ds.Tables(0)
        Catch ex As Exception
        End Try
    End Sub

When I open the form the routine works to the point where I can see all six items in the combobox. The problem I'm getting now is when I click on the Oracle item; the DBID being returned is zero(0), clicking on Microsoft SQL Server will result with a one(1), and so on.

I know all collections are zero-based. But what I want to know is why doesn't .NET assign the index to the DBID? Isn't the .NET way of doing things suppose to be better? What is the use of building a DataSet, but have to populate the Combobox using ADO techniques used in VB6? I have never seen a database table where a zero can be used as a identification number in a Primary Key field.

Thanks in advance,
Posted 28-Mar-13 11:22am
Sergey Alexandrovich Kryukov 28-Mar-13 16:33pm
Please tag the UI library you use or application type. If could be ASP.NET or System.Windows.Forms...
Sergey Alexandrovich Kryukov 28-Mar-13 16:34pm
Don't catch and handle exception locally. Let go. It should be handled way up the stack...

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

I have found my own answer.
'This sets the combobox.ValueMember to the
'number in the DBID column(field) of the dataset.
'I believe the ValueMember Method replaces the
'NewIndex method in VB6.
ComboBox.ValueMember = "DBID"

When I selected a database type from the combobox and looked at the ValueMember property I could then see the DBID number I needed.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.1802120.2 | Last Updated 12 Apr 2013
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100