View Single Post
 
Old July 7th, 2008, 01:39 AM
greenbriar greenbriar is offline
Authorized User
Points: 68, Level: 1
Points: 68, Level: 1 Points: 68, Level: 1 Points: 68, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2007
Location: Hansville, WA, USA.
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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
        objConnection.Open()

        '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
        objDataAdapter.Fill(objDataTable)

        '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.

Greenbriar