Hi,
I have a datagridview.And as per my requirement the data is supposed to be filled from three different tables in database.I have created the query and is succesfully able to populated the data in it with the cross join.
Have a look at my structure.
Table1,Table2,Table3.
table1 has 2 records.
Table2 has 7 records.
and Table 3 has 15 records.
Below is my code that reads data from Cross Join Query

If dr.HasRows Then
            While dr.Read
                combo1.Items.Add(dr(0))
                combo2.Items.Add(dr(1))
                combo3.Items.Add(dr(2))
            End While
        End If

my query
strquery="Select Table1.Column1,Table2.Column1,Table3.Column1 from Table1 cross join Table2 cross join table3"

It is giving me duplicate records.Please give me logic to do it correctly.

Please check ur join condition and pass more info on Query

these are the only three columns from which im fetching the data and populating in DatagridView.
I just want the logic to skip if the record is repeating.Its showing duplications because different columns are having different count of records.And its looping that number of times in while.

Cross join without a where is supposed to deliver a cartesian product: http://msdn.microsoft.com/en-us/library/ms190690.aspx
You should join your tables using keys that will make unique joins record to record from one table to another.

You could find that the same result is for now achieved using a distinct ie:

select distinct table1.field1,table2.field1,table3.field1 from table1 cross join table2 cross join table3

but it is a bad practise as the results in the long run might not be the ones expected. Use at your own risk.

Hi frnds done with my Issue.
Im just checking in the combobox that weather the data in dr already exists in combo or not.This way

if combo1.Items.Contain(dr(0))=false then
combo1.Items.Add(dr(0))
end if

Thanks for the help guys

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.