Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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
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



Reply With Quote
  #2 (permalink)  
Old July 19th, 2008, 02:27 AM
Registered User
 
Join Date: Jul 2008
Location: , , .
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
Reply With Quote
  #3 (permalink)  
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
Location: Hansville, WA, USA.
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


Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 10:06 AM.


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