0

hello.. i have problem load two data from different table and column.. for example, each data from product table into product combobox and brand table to brand combobox..i succussfully load data to combobox but got multiple same data into combobox..

Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;Data Source=" & Application.StartupPath & "\mydatabase.mdb;Jet OLEDB:Database Password=admin;")

        Dim cmd As OleDbCommand = New OleDbCommand("SELECT product.productN,brand.brandN FROM product, brand", conn)

        conn.Open()

        Dim sdr As OleDbDataReader = cmd.ExecuteReader

        While sdr.Read()

            product.Items.Add(sdr.Item("productN").ToString)
            brand.Items.Add(sdr.Item("brandN").ToString)



        End While

        conn.Close()

    End Sub

Edited by arezz09

Attachments 3.jpg 28.92 KB 2.jpg 8.59 KB 4.jpg 51.75 KB 1.jpg 9.96 KB
4
Contributors
4
Replies
32
Views
3 Years
Discussion Span
Last Post by ryanjayson
0

make proper use of distinct in your select statement.

try this(i am not sure)

"SELECT distinct product.productN,brand.brandN FROM product, brand
0

this happens due to two reasons
1.You haven't put a primary key
2.put a two condition seperately for two comboboxes

Edited by Dili1234: still witing

0

Try this one dude:

Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;Data Source=" & Application.StartupPath & "\mydatabase.mdb;Jet OLEDB:Database Password=admin;")
        Dim cmd As OleDbCommand = New OleDbCommand("SELECT product.productN,brand.brandN FROM product FULL JOIN brand ON product.productN = brand.brandN", conn)
        conn.Open()
        Dim sdr As OleDbDataReader = cmd.ExecuteReader
        While sdr.Read()
              If Not sdr("ProductN").ToString = String.Empty Then product.Items.Add(sdr.Item("productN").ToString)
              If Not sdr("brandN").ToString = String.Empty Then brand.Items.Add(sdr.Item("brandN").ToString)
        End While
        conn.Close()
    End Sub
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.