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,Mode l,Color, Miles FROM dbo.VehicleMaster ORDER BY StockNumber"
Try
cmd.Connection.Open()
dr = cmd.ExecuteReader
While dr.Read
lstStocknumberList.Items.A dd(dr.GetV alue(dr.Ge tOrdinal(" StockNumbe r")).ToStr ing)
End While
Catch ex As SqlException
MessageBox.Show(ex.Message )
Finally
cmd.Connection.Close()
End Try
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,Mode
Try
cmd.Connection.Open()
dr = cmd.ExecuteReader
While dr.Read
lstStocknumberList.Items.A
End While
Catch ex As SqlException
MessageBox.Show(ex.Message
Finally
cmd.Connection.Close()
End Try
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER