Link to home
Start Free TrialLog in
Avatar of Matrix1000
Matrix1000

asked on

Select list item thenQuery Database with generic query?

I have a listbox with my stock#'s. I have a query string to SQL that can pull the data I need.

My question is how could I select a stock# on the list and automatically proform a query for the selected stock# details to return the year, make, model etc to some labels on my form.

Heres what I have so far for a connection and query...

Dim conn As New SqlConnection("My connection string;")
        Dim cmd As New SqlCommand
        Dim dr As SqlDataReader

        cmd.Connection = conn
        cmd.CommandType = CommandType.Text
        cmd.CommandText = "SELECT StockNumber,Year,Make,Model,Color, Miles FROM dbo.VehicleMaster ORDER BY StockNumber"

        Try
            cmd.Connection.Open()
            dr = cmd.ExecuteReader
            While dr.Read
                lstStocknumberList.Items.Add(dr.GetValue(dr.GetOrdinal("StockNumber")).ToString)
            End While
        Catch ex As SqlException
            MessageBox.Show(ex.Message)
        Finally
            cmd.Connection.Close()
        End Try
SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Matrix1000
Matrix1000

ASKER

Well in the list box I want to show 4 items...but when you click on an item in the list it fills some textboxes with additional information from that record...like Miles,VIN,Price, etc that is associated with that Stock#
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial