Problem with queries: Access to VB (1 Viewer)

allok58

New member
Local time
Today, 00:23
Joined
Jun 8, 2011
Messages
1
Is there a way to make specific queries from a specific table to another, and then export it to VB??. I have an access database, in which I have 4 tables and 1 query. There is one table called "Customers","Gears" and "Articles"; the last one is the relationships with the ID between the tables from Articles, Gears and Customers, becuase a customer may have more than two Gears, therefore the Articles as well.
So in VB I made an interface in which it conects to the database to show in a combobox all the customers, after that if I choose a customer, then it is supposed to show de gear in a listbox which the customer has, but the problem is that it shows all the gears from the query and not the specific one from that customer, also it repeats in the listbox the same gear twice or more. I think it is problem from my query, but I really don't know how to use very well Access, so I am depending on VB.
This is the code that I got so far (Note in my code: Cliente = Customers; Gear = Equipo; Articles = Articulos)

Code:
Imports System.Data.OleDb
Public Class frmConsulta

    Dim DBConnection As New OleDbConnection
    Dim DBCommand As New OleDbCommand
    Dim DBReader As OleDbDataReader

    Private Sub frmConsulta_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load  
        DBConnection = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=C:\Users\Administrador\Documents\ProyectoGlobalMantenimiento.accdb; Persist Security Info = False;")
        DBCommand = New OleDbCommand("Select Cliente from Clientes", DBConnection)
        DBConnection.Open()
        DBReader = DBCommand.ExecuteReader()
        cboxCliente.Items.Clear()
        Do While DBReader.Read()
            Me.cboxCliente.Items.Add(DBReader(0))
        Loop
        DBReader.Close()
        DBConnection.Close()
    End Sub

    Private Sub cboxCliente_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboxCliente.SelectedIndexChanged
        If cboxCliente.SelectedIndex Then
            DBConnection = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=C:\Users\Administrador\Documents\ProyectoGlobalMantenimiento.accdb; Persist Security Info = False;")
            DBCommand = New OleDbCommand("Select Equipos.[Generador o Equipo] from Equipos INNER JOIN (Clientes INNER JOIN (Artículos INNER JOIN Relaciones ON Artículos.[Clave] = Relaciones.[Clave]) ON Clientes.[IdCln] = Relaciones.[IdCln]) ON Equipos.[IdGn] = Relaciones.[IdGn]", DBConnection)
            DBConnection.Open()
            DBReader = DBCommand.ExecuteReader()
            lsteq.Items.Clear()
            Do While DBReader.Read()
                Me.lsteq.Items.Add(DBReader(0))
            Loop
            DBReader.Close()
            DBConnection.Close()
        End If
    End Sub

    Private Sub lsteq_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lsteq.SelectedIndexChanged
        If lsteq.SelectedIndex Then
            DBConnection = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=C:\Users\Administrador\Documents\ProyectoGlobalMantenimiento.accdb; Persist Security Info = False;")
            DBCommand = New OleDbCommand("Select Artículos.[Descripción del artículo] from Equipos INNER JOIN (Clientes INNER JOIN (Artículos INNER JOIN Relaciones ON Artículos.[Clave] = Relaciones.[Clave]) ON Clientes.[IdCln] = Relaciones.[IdCln]) ON Equipos.[IdGn] = Relaciones.[IdGn]", DBConnection)
            DBConnection.Open()
            DBReader = DBCommand.ExecuteReader()
            lstar.Items.Clear()
            Do While DBReader.Read()
                Me.lstar.Items.Add(DBReader(0))
            Loop
            DBReader.Close()
            DBConnection.Close()
        End If
    End Sub
End Class

You would help me a lot if you can suggest or make me a correction. Thanks.:)
 

izaak

New member
Local time
Today, 00:23
Joined
May 8, 2012
Messages
2
i have no clue on how to do it but this page here shows allot about the request you have , so i hope this website helps you out.

vbtutor.net/vb6/lesson29.html

i cant post website yet so i had to cut it up :)
 

elzaiem

New member
Local time
Today, 10:23
Joined
Aug 30, 2012
Messages
1
Hellow everybody
 

Users who are viewing this thread

Top Bottom