Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Add Items to Combobox VB 2010

Posted on 2011-02-19
9
Medium Priority
?
4,334 Views
Last Modified: 2012-05-11
Hello all,

I have another issue when i want to add items in my combobox. If is feed by the link in my Parametre.txtBaseDelabsolution.Text.

This is the error:
Error      2      'AddItem' is not a member of 'System.Windows.Forms.ComboBox'.



 
 Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Nom de famille
        Dim sSQL3 As String
        Dim oConnect3 As ADODB.Connection
        oConnect3 = New ADODB.Connection
        Dim oRST3 As ADODB.Recordset
        oRST3 = New ADODB.Recordset


        sSQL3 = "SELECT DISTINCT[nom]FROM [Clients]'"

        oConnect3.Open("Provider=Microsoft.ACE.OLEDB.12.0;" & _
        "Data Source=" & Parametre.txtBaseDelabsolution.Text)

        Me.Nom_famille.AddItem("")
        oRST3.Open(sSQL3, oConnect3)
        Do Until oRST3.EOF
            Me.Nom_famille.AddItem(oRST3("Nom"))
            oRST3.MoveNext()
        Loop

    End Sub

Open in new window


Thanks again for you help
0
Comment
Question by:Wilder1626
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 29

Expert Comment

by:Paul Jackson
ID: 34934353
The method .AddItems() has been replaced with .Items.Add()
You need to use Me.Nom_famille.Items.Add(oRST3("nom"))
0
 
LVL 29

Expert Comment

by:Paul Jackson
ID: 34934419
a good link on the differences between vb6 and vb2010 :

http://msdn.microsoft.com/en-us/library/fte6kbt2(v=vs.80).aspx
0
 
LVL 11

Author Comment

by:Wilder1626
ID: 34935128
Hello,

Now it feeds my combobox but not with what i'm suppose to.

I have full list of: ADODB.InternalField.

What could it be?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 29

Expert Comment

by:Paul Jackson
ID: 34935148
Hmm didn't notice before but looks like you are trying to use ADO rather than ADO.Net have a look at the link below for an overview of retrieving records from a database using ado.net:

http://asp.dotnetheaven.com/howto/doc/adoplus/sqldtreader.aspx
0
 
LVL 11

Author Comment

by:Wilder1626
ID: 34935323
What is the diffrence?

What i could say is that i was using the code in my first post with VB6 with a data base from Microsoft Access 2007.
0
 
LVL 29

Expert Comment

by:Paul Jackson
ID: 34935413
But you are using VB.net now ?

anyway i think you can change your existing code as follows by adding a .movefirst before the loop. I suggest you do look into ado.net as it hadles disconnected recordsets like you are trying to do above better and more efficiently.

 Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 
        'Nom de famille 
        Dim sSQL3 As String 
        Dim oConnect3 As ADODB.Connection 
        oConnect3 = New ADODB.Connection 
        Dim oRST3 As ADODB.Recordset 
        oRST3 = New ADODB.Recordset 
 
 
        sSQL3 = "SELECT DISTINCT[nom]FROM [Clients]'" 
 
        oConnect3.Open("Provider=Microsoft.ACE.OLEDB.12.0;" & _ 
        "Data Source=" & Parametre.txtBaseDelabsolution.Text) 
 
        Me.Nom_famille.AddItem("") 
        oRST3.Open(sSQL3, oConnect3) 

     If Not oRST3.EOF Then
        oRST3.MoveFirst
        Do Until oRST3.EOF 
            Me.Nom_famille.AddItem(oRST3("Nom")) 
            oRST3.MoveNext() 
        Loop 
 
    End If

    End Sub 

Open in new window

0
 
LVL 11

Author Comment

by:Wilder1626
ID: 34935441
I have tried your code above but i have the same result with: ADODB.InternalField.
0
 
LVL 29

Accepted Solution

by:
Paul Jackson earned 2000 total points
ID: 34935450
I forgot .Net no longer has default values like vb6 had you need to specify the attribute you want to retrieve.

Change this line : Me.Nom_famille.AddItem(oRST3("Nom")) to Me.Nom_famille.AddItem(oRST3("Nom").Value)
0
 
LVL 11

Author Closing Comment

by:Wilder1626
ID: 34935463
This is perfect.

Thanks for your help.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question