Wrox Programmer Forums
|
VB.NET General VB.NET discussions for issues that don't fall into other VB.NET forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 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 March 13th, 2006, 11:29 PM
Authorized User
 
Join Date: Nov 2005
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default ComboBox & ListBox usage

Dear all,

In VB .NET 2003 - how to list a particular column values of a particular table in a Combo box. Kindly give me a sample code list, so that I can understand the same in a sequence.

Expecting your reply with necessary Sample code list.



VENKATESH
__________________
VENKATESH
 
Old March 14th, 2006, 05:58 AM
Authorized User
 
Join Date: Nov 2005
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This is how i populate a combo box from 1 particular column in a MS Access database.

        Dim Cmd As OleDb.OleDbCommand
        Dim Con As OleDb.OleDbConnection
        Dim Sql as String = nothing

        Dim ComboRow As Integer = -1
        Dim Columns As Integer
        Dim Category As String = Nothing

        CmbBoxMan.Items.Clear()

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

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

----------------------------

I hope this works. Please let me know how you get on.

Pete*

 
Old March 14th, 2006, 07:35 AM
Authorized User
 
Join Date: Nov 2005
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Dear peter,

Thanks for ur quickest reply. I have tried with your sample but I am not able to understand the "Reader" data type?

please explain to me?

venki

VENKATESH
 
Old March 14th, 2006, 07:46 AM
Authorized User
 
Join Date: Nov 2005
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Dear Peter,

Thanks for your sample code, it is working. Your example shows OLEDB but I am using SQLServer. Here is my sample for all our members use.
Thanks once again.

        Dim cmd As New SqlCommand
        Dim reader As SqlDataReader
        'Dim con As New SqlConnection
        Dim sql As String = Nothing
        Dim comborow As Integer = -1
        Dim columns As Integer
        Dim category As String = Nothing
        ComboBox1.Items.Clear()
        sql = "select sordernum from soconfirm"
        cmd = New SqlCommand(sql, tstsqlconn)
        tstsqlconn.Open()
        reader = cmd.ExecuteReader
        While reader.Read()
            For columns = 0 To reader.FieldCount - 1
                category = reader.Item(columns)
            Next
            ComboBox1.Items.Add(category)
            comborow += 1
        End While

VENKATESH
 
Old March 14th, 2006, 07:50 AM
Authorized User
 
Join Date: Nov 2005
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry :D Add the following Dim statement with the other Dims.

  Dim Reader As OleDb.OleDbDataReader

Sorry about that. I declare all my Dims in one module. That way I don't have to worry about re-creating them later on while programming.

Any other problems, please let me know. Also let me know how you get on with the code. What database r u using?

Thanks

Pete*






Similar Threads
Thread Thread Starter Forum Replies Last Post
Filling a combobox/listbox unmeshraut VB How-To 1 September 21st, 2007 12:08 PM
comboBox & ReadOnly melvik C# 12 February 12th, 2004 01:50 PM
ComboBox, ListBox tpsmith78 VS.NET 2002/2003 1 January 23rd, 2004 04:36 PM
comboBox & ReadOnly melvik C# 2 October 29th, 2003 12:45 AM





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