3
Contributors
3
Replies
15
Views
3 Years
Discussion Span
Last Post by ryanjayson
0

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.

0
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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.