Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
|
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 7th, 2008, 01:39 AM
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
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



 
Old July 19th, 2008, 02:27 AM
Registered User
 
Join Date: Jul 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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;"



Pauline,
http://www.TecTalkTraining.com
 
Old July 22nd, 2008, 10:18 PM
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
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Pauline:

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.

Greenbriar







Similar Threads
Thread Thread Starter Forum Replies Last Post
Populate drop down list with XML file rlull ASP.NET 1.0 and 1.1 Basics 5 November 30th, 2013 12:15 PM
Populate a List Box with Table Names & Table date hewstone999 Access VBA 1 February 27th, 2008 10:10 AM
how to populate a table with xml data in xslt miccipynewbie XSLT 6 May 28th, 2007 07:29 AM
populate drop down list with a function code3hree Javascript 1 May 28th, 2005 11:44 AM
populate data from Access Table into datagrid bisigreat VB How-To 6 August 17th, 2004 06:58 AM





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