473,385 Members | 1,615 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to use cross join to show data in datagridview.

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
Expand|Select|Wrap|Line Numbers
  1. If dr.HasRows Then
  2.             While dr.Read
  3.                 combo1.Items.Add(dr(0))
  4.                 combo2.Items.Add(dr(1))
  5.                 combo3.Items.Add(dr(2))
  6.             End While
  7.         End If
  8.  
  9. my query
  10. strquery="Select Table1.Column1,Table2.Column1,
  11. Table3.Column1 from Table1 cross 
  12. join Table2 cross join table3"
  13.  
It is giving me duplicate records.Please give me logic to do it correctly.
Sep 13 '11 #1
6 1977
Rabbit
12,516 Expert Mod 8TB
A cross join will join every record to every other record. That's what it's supposed to do. Without knowing how you define a duplicate and a sampling of the data, you've given us no information that we can use to help you resolve your problem.
Sep 13 '11 #2
hi Rabbit,
Above is my exact code its just that i have only truncated the names of my Database tables and combobox.What is hapenning is i suppose i have 3 record in Table1 and 5 in table2 then 3 multiplied by 5=15 thats what the number of records which are obviously duplicated records and such result is expected from cross join.i wanted some guidance that in while reading a row through Dr can i check wheather this particular records is already added to my combo or not.If not added than it should add if yes than it should skip.
Sep 14 '11 #3
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
Expand|Select|Wrap|Line Numbers
  1. if combo1.Items.Contain(dr(0))=false then
  2. combo1.Items.Add(dr(0))
  3. end if
  4.  
Sep 14 '11 #4
Rabbit
12,516 Expert Mod 8TB
You still haven't told us how you know a record is duplicated nor did you give us a sample of the data.

A cross join creates no "duplicated" records if there was no duplicated records in the original tables. Duplication is a business logic issue.
Sep 14 '11 #5
Hi,
actually i used the wrong term may as duplication.
My issue was the records were getting repeated.Like just for an example
I have a Designation master which has only 3 designations in it
MD,CEO,President.But when i was running the Query and the data was getting filled using dr it was repeatedly adding the same records again till the loop was executing.
Like my table1 had 3 records and table2 had 5 so it was executing 15 times because of cross join and getting my each designation value number of times.
I hope this has cleared what exactly my question was.
If needed can provide with further explanation.
Thanks for support
Sep 14 '11 #6
Rabbit
12,516 Expert Mod 8TB
If you only need the one column from the one table. You shouldn't be joining to the other tables in the first place.
Sep 14 '11 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Klint Gore | last post by:
I've hit a situation where I'm getting an unexpected set of results from a cross join that I've narrowed down to a table alias. If I do (a has 4 rows, b has 1 row) select a.field1, b.* from a...
5
by: PawelR | last post by:
Hello Group, Sorry my english is very little. I have problem with show data from Table from DataSet in textBox. In my apps I have "typed DataSet" myDS with table TabPerson On Form I have...
11
by: chettiar | last post by:
I have a SQL Server code which goes like this: UPDATE ms SET c1 = ms.c1 + ur.c1 FROM test ms CROSS JOIN test ur WHERE ms.c2 = 'a' AND ur.c2 = 'b'
0
by: MathewJose | last post by:
Hi, How do we create a datatable in which you can join the data from excel sheet and db ?I need to use the new table as the datasource IPlz help!!!
3
by: Mirnes | last post by:
Hello! How can I show data outside of data controls (gridview, listview etc.). I want to build CSS menu with data from database table and that is the reason why I need it outside of any data...
0
by: metaperl | last post by:
How can I cross join all rows of table A with 1000 rows (first 1000, any 1000) of table B?
1
by: Jackmac | last post by:
Hi there, Hopefully an easy one for someone. I'm writing a small app (Visual Studio 2008) which will take an existing access database we have and show it in a form I'm writing. The fields have...
3
atksamy
by: atksamy | last post by:
I have 2 tables like which i would like to query to form a new table. table 1 number type serial index 1000001 613 3 1 1000001 613 3 ...
8
by: obtrs | last post by:
show data of multiple tables? i have 3 tables i want to show the data from them to a page. table1 "trip" table2 "seat" table3 "user_information" show all the data of table one which is...
2
by: binui | last post by:
I have a table with fields facility,shift,line,date,No; of Items of size <7mm. I've to write a query to display the total no:of items having size <7mm in each line of a particular shift, of a...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.