Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Select list item thenQuery Database with generic query?

Posted on 2005-05-05
Medium Priority
Last Modified: 2006-11-18
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"

            dr = cmd.ExecuteReader
            While dr.Read
            End While
        Catch ex As SqlException
        End Try
Question by:Matrix1000
LVL 96

Assisted Solution

by:Bob Learned
Bob Learned earned 150 total points
ID: 13939407
Which way are you looking to do it:

Multiple columns?

or labels?


Author Comment

ID: 13940601
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#

Accepted Solution

doobdave earned 1350 total points
ID: 13943422
Hi Matrix,

a couple of suggestions:

1) Your first query could return only the info that goes into the listbox.
When an item is selected, you retrieve the value ( .SelectedValue property, i believe), and execute another quey, passing that value as a parameter, to retrieve the data you need to populate the other txt boxes.

This method may be slow as you are hitting the db twice, but it depends on the amonut of data in the db table.

2) Select all the information in your first query, and use a dataAdapter to populate a dataset.
Then, use a dataview object, and when user makes a selection, set the .Rowfilter property of the dataview. You can then set the text in your textboxos to the appropriate items in the dataview row.



Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question