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

x
?
Solved

Select list item thenQuery Database with generic query?

Posted on 2005-05-05
3
Medium Priority
?
344 Views
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"

        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
0
Comment
Question by:Matrix1000
3 Comments
 
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?
http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_21414334.html

or labels?

Bob
0
 
LVL 1

Author Comment

by:Matrix1000
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#
0
 
LVL 8

Accepted Solution

by:
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.

Regards,

David
0

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