Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
|
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To 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 April 4th, 2004, 10:49 AM
Registered User
 
Join Date: Apr 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to drpcken
Default How 2 fill a dropdownlist with a column in sql

This is so frustrating, i've tried so many things. Here's what I have so far, but nothing I do after this wants to work.

        'Create the connection
        Dim sqlconnection As New SqlClient.SqlConnection()
        sqlconnection.ConnectionString = "server=hal/sbmtwo;uid=sa;password=;initial catalog=SBM01"

        'Create the Dataset
        Dim dsVendor As New DataSet()

        'Create the DataAdapter
        Dim daVendor As New SqlClient.SqlDataAdapter("select VENDORID,VENNAME from PM00200", sqlconnection)

        'Fill the dataset
        daVendor.Fill(dsVendor, "PM00200")

Right now I should have a dataset filled with the columns I need correct? How do I get that VENDORID column into a drop down list called ddlVendorID?

Thank you guys!
 
Old April 5th, 2004, 07:21 AM
Authorized User
 
Join Date: Jun 2003
Posts: 91
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I do not use an SQL backend but the result should be the same. Gove this a shot.

With rst
   Do Until .EOF
      'Populate frmLogin.cboUserName
      frmLogin.cboUser.AddItem !FullName
      .MoveNext
   Loop
End With

rst.Close
Set rst = Nothing

Works a charm at filling a ComboBox. Hope this helps.

Kenny Alligood
 
Old April 17th, 2004, 09:34 PM
Registered User
 
Join Date: Apr 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I wrote this code several years ago in VB6. I was using an Access database on the backend. Hope this helps.
Code:
Public Sub PopProgrammer()
'This fuction populates Assigned Programmer's combobox field on the FrmUtility form
'when the application is executed.
Set WrkSpce = CreateWorkspace("", "admin", "", dbUseJet) ' Create the workspace
Set db = DAO.OpenDatabase("C:\Program Files\IssuesLog\MsgUtil.mdb", False, False) ' Set the Database
SQLString = "SELECT * FROM ProgNameTbl" ' this query selects all of the records in the table
Set QryTbl = db.CreateQueryDef("") ' Create a Query definition object
    QryTbl.SQL = SQLString         ' Set the Query def object to the SQL String
    Set rs = QryTbl.OpenRecordset  ' execute the query
If rs.BOF = True And rs.EOF = True Then ' If EOF or BOF then...
    Reply = MsgBox("An Application error has occurred, Contact the application administrator.", vbOKOnly, "Uh Oh!")
    '...Display message box
Else                                                'otherwise
    rs.MoveFirst                                    'move to first record on recordset
    While rs.EOF = False                            'perform loop until EOF
        CboProgrammer = rs.Fields("AssgProg")       'Assign field in record to variable
        frmUtility.cboAsgnProg.AddItem CboProgrammer 'Add item to Combo box
        rs.MoveNext                                 'move to next record
    Wend                                            'End While loop
    rs.Close                                        'Close recordset
    db.Close                                        'Close Database
End If                                              'End if
End Sub





Similar Threads
Thread Thread Starter Forum Replies Last Post
Rename a Column using SQL pipelineconsulting Classic ASP Databases 7 September 21st, 2017 04:16 PM
Sql Update Stament via DropDownlist in GridView DarkForce ASP.NET 2.0 Basics 7 August 8th, 2007 09:08 AM
Multi column Dropdownlist control??? MTLedari ASP.NET 2.0 Basics 6 June 7th, 2007 11:40 PM
Fill Spreadsheet with 2 separate SQL Queries rweide Classic ASP Databases 0 February 16th, 2005 11:35 AM
Hard SQL/Fill list Question MichaelTJ ADO.NET 1 October 27th, 2003 12:52 PM





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