Wrox Programmer Forums
|
Pro VB 6 For advanced Visual Basic coders working in version 6 (not .NET). Beginning-level questions will be redirected to other forums, including Beginning VB 6.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB 6 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 June 28th, 2007, 12:51 PM
Registered User
 
Join Date: Jun 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default hi all

hi all,

Iam new to VB iam trying to populate the combo box with the table item from SQL database(ODBC).

My code returns nothing into combo box.

when i debug ,the combo box shows nothing

here is my code
Dim Cmd As Odbc.OdbcCommand
        Dim Con As Odbc.OdbcConnection
        Dim Sql As String = Nothing
        Dim Reader As Odbc.OdbcDataReader
        Dim ComboRow As Integer = -1
        Dim Columns As Integer = 0
        Dim Category As String = Nothing
        Dim Cmbbox As ComboBox

        CmbboxMan.Items.Clear()

        Con = New OleDb.OleDbConnection("Provider=Microsoft.Jet.OleD b.4.0;data source=" & Database & "")
        Sql = "SELECT [Comp_ItemNumber] FROM [Components] ORDER BY [Comp_ItemNumber] Asc"
        Cmd = New Odbc.OdbcCommand(Sql, Con)
        Con.Open()

        Reader = Cmd.ExecuteReader()
        While Reader.Read()
            For Columns = 0 To Reader.FieldCount - 1
                Category = Reader.Item(Columns) 'READ COLUMN FROM DATABASE
            Next
            Cmbbox.Items.Add(Category)
            ComboRow += 1
        End While
        Con.Close()

URGENT reply me ASAP


 
Old June 28th, 2007, 01:13 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there..

is the Query returning something?? b/c this line
Code:
Reader.Item(Columns)
seems weird to me because there are no column named colums..

also, you are filing items in cmbbox, that are dimmed inside the function and probably is not the one on the form (Dim Cmbbox As ComboBox, CmbboxMan.Items.Clear() are diferents combos!)

also.. this is a vb6 forum and your code is vb.net ;)

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========









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