Hi All,

I need help in displaying a list (Sl.no) from a database to combo box. Please help me....

Recommended Answers

All 3 Replies

How about a little more detail?

I am looking for a code which can get the sl.no's from the database into a combo box, when I select the number from Combo box it should display the rest of the contents like, Price, description, Manufacturer.

Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    'Specify the datasource
    Dim CONNECTION_STRING As String = "Data Source=LOCALHOST;Initial Catalog=DB_NAME; Integrated Security=True"

    Dim conn As SqlConnection = New SqlConnection(CONNECTION_STRING)
    'Specify the SELECT query
    Dim cmd As SqlCommand = New SqlCommand("SELECT ProductName FROM ProductTable", conn)



    'Open the Database
    conn.Open()

    Dim sdr As SqlDataReader = cmd.ExecuteReader

    'Do the adding through looping
    While sdr.Read()
        If Not sdr("ProductName").ToString = String.Empty Then product.Items.Add(sdr.Item("ProductName").ToString)

    End While

    'Close the Database
     conn.Close()

End Sub

Thats the code on loading item from databasae to combobox, now figure out with yourself on how to select and display the other info of selected item.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.