Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB Databases Basics
|
VB Databases Basics Beginning-level VB coding questions specific to using VB with databases. Issues not specific to database use will be redirected to other forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB Databases Basics 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 29th, 2007, 03:03 PM
Registered User
 
Join Date: Jul 2007
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Making ComboBox to display the List from DB table

Hi Guys,

Please, please can anyone help. I seem to be stuck with a problem, I have created tables in SQL Server 2005 Express with the following definitions:

Customer
    [Customer ID]
    [NAME] nvarchar(100),
    [CONTACT_NAME] nvarchar(60),
    [CONTACT_1] nvarchar(100),
    [CONTACT_2] nvarchar(50),
    [CITY_TOWN] nvarchar(70),
    [PROVINCE] varchar(50),
    [COUNTRY] varchar(100)

Country
  [COUNTRY NAME]
  [City]

I have created a user-interface with Visual Basic Express 2005. So what steps do I use to link a CountryComboBox on the user-interface form to the table - Country [COUNTRY NAME]? So that the CountryComboBox can display the list of countries from the - database table - Country for the user. Thanks a lot.


 
Old August 1st, 2007, 05:55 PM
Registered User
 
Join Date: Jul 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I do not know if this will work for what you want, but this is what I use with vb6 to open a database and load a listbox.

Code:
Private Sub Command1_Click()
Dim cn As New ADODB.Connection


    List1.Clear


    With cn 'database
   
        cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & App.Path & "\DataBase Name.mdb;"

    End With

 
Set rs = New ADODB.Recordset 'as we did with the connection
rs.Open "databaseName", cn, adOpenKeyset, adCmdTable 'opening the recordset 
      
      
      With List1 'this will add to a list bpx called List1

      Do While Not rs.EOF       
      .AddItem rs.Fields("database record")'Change the name of the field here to the one you want to show
      .Refresh
      rs.MoveNext
      Loop

    End With

  rs.close  ' tidy up things
  set rs = nothing 
 
end sub     





Similar Threads
Thread Thread Starter Forum Replies Last Post
Data Bind ComboBox to display the List Bjay Pro VB Databases 0 July 29th, 2007 02:57 PM
Populating master table with list from list table sburgess Access 7 September 1st, 2006 06:03 AM
Making changes to DB on hosting server w/ VS.NET ltdanp21 SQL Server 2000 5 June 18th, 2004 01:28 PM
Making changes to DB on hosting server w/ VS.NET ltdanp21 VS.NET 2002/2003 1 June 15th, 2004 03:55 PM
making a db field link on a page doranaz Classic ASP Databases 0 December 19th, 2003 01:13 PM





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