p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ADO.NET (http://p2p.wrox.com/forumdisplay.php?f=109)
-   -   populate a drop list fro a data table (http://p2p.wrox.com/showthread.php?t=69192)

greenbriar July 7th, 2008 01:39 AM

populate a drop list fro a data table
The code with the proble follows"

 Private Sub LoadModes()

        Dim modesrowcount As Integer

        'Initialize a new instance of the OleDbConnection class
        objConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; " & _
            "Data Source=" & My.Forms.frmLocateDb.txtDatabase.Text & ";")

        'Open the connection

        'Create the search query for the call signF
        strStoredSQL = "SELECT * FROM MODES;"

        'Declare and inititialize a new instance of the OleDbCommand class
        Dim objCommand As New OleDbCommand(strStoredSQL, objConnection)

        'Set the Command Type property
        objCommand.CommandType = CommandType.Text

        'Declare a OleDbDataAdapter object
        Dim objDataAdapter As New OleDbDataAdapter

        'Set the SelectCommand for the OleDbDataAdapter
        objDataAdapter.SelectCommand = objCommand

        'Initialize the DataTable object
        Dim objDataTable As New DataTable

        'Populate the DataTable

        'Count the rows in the data table
        modesrowcount = objDataTable.Rows.Count

        'Bind the BindingSource to the daaset
        MODESBindingSource.DataSource = objDataTable

        cmbModes.DataSource = MODESBindingSource
        cmbModes.DisplayMember = "Modes"

    End Sub

I'm trying to populate the drop down list fo cmbModes with the data in a table named MODES in the database. The table contains one field named Modes with 9 rows.

When I run the procedure, the list box shows the nine rows but all the rows contain the statement "System.Data.DataRowView". I proved that the datatable contains 9 rows of data by the modesrowcount variable which comes back with the value of 9 and looking at the table in Access.

What do I need to do to correct the problem.


Pauline123 July 19th, 2008 02:27 AM

This error occurs when the field name is not exactly matched to the binding lines.
Try change the select statement to "SELECT Modes FROM MODES;"


greenbriar July 22nd, 2008 10:18 PM


Thanks for the advice. It's the clue that solves the problem. I have 3 books on VB 2005 programming and I'm surprised that none of them include this as a warning. This includes 2 from WROX. My last version of VB I programmed with was 4.0 and there have been many changes in the programming modes so it's like learning a new language.


All times are GMT -4. The time now is 02:50 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.