Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sql query using oledb in a progressive combobox fill 1

Status
Not open for further replies.

bamauto

Programmer
Oct 21, 2009
8
US
Need some help,
I'm using vb2008
oledb connection
I have one table in an access database with 4 important fields to find the result of a search through combobox selection.
EX.
combobox1 query on form load fills combobox1 with YEAR selection from database.
VEHICLEDATA database has fields of YEAR, MAKE, MODEL, ENGINE, FILTERNUMBER, ENGINECAPACITY.
as you can see we are looking up oil filter numbers by
vehicle application.
User selects the YEAR first from combobox1, the next step I can't quite figure the query....
Using combobox1 click event need to query for combobox2 to load its values based on a progressive type query.
i'm not real familiar with select statement, could someone help.
Eventually i want to fill remaining comboboxes for selection
progressively.

select year, select make, select model, select engine.
this order will eventually retreive the oil filter number and engine oil capacity from the database
This is the current code:

Imports System.Data.OleDb
Public Class Form1
Inherits System.Windows.Forms.Form
Dim cn As OleDbConnection
Dim cmd As OleDbCommand
Dim dr As OleDbDataReader



Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

'Load combobox1 with year data for initial start
Try
cn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\VehicleData.accdb")
cn.Open()
cmd = New OleDbCommand("SELECT DISTINCT [Year] FROM(VehicleData) ORDER BY [Year] DESC", cn)
dr = cmd.ExecuteReader
While dr.Read
ComboBox1.Items.Add(dr(0))
End While
Catch
End Try
dr.Close()
cn.Close()
'End combobox1 initial load


End Sub


End Class
 


Hi,

I assume that you're doing this IN Access?

If so, please post in forum705 for better results.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Thanks for the reply.
No, I'm using vb2008 to build a user application.
 

This is really VB 2008 question and you should ask this in other Forum, but try something like:
Code:
    Private Sub [blue]ComboBox1_SelectedIndexChanged[/blue](ByVal sender As System.Object, _
            ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged

        'Load combobox2 with make data for initial start
        Try
            cn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\VehicleData.accdb")
            cn.Open()
            cmd = New OleDbCommand("SELECT DISTINCT [Make] FROM(VehicleData) " _
            [blue]& " WHERE [Year] = " & ComboBox1.Text & " ORDER BY [Make][/blue] ", cn)
            dr = cmd.ExecuteReader
            [blue]ComboBox2.Items.Clear[/blue]
            While dr.Read
                [blue]ComboBox2.Items.Add(dr(0))[/blue]
            End While
        Catch
        End Try
        dr.Close()
        cn.Close()

    End Sub

Have fun.

---- Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top