Compare 2 Tables - Return Rows VB 2008

Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: May 2007
Posts: 45
Reputation: cellus205 is an unknown quantity at this point 
Solved Threads: 1
cellus205 cellus205 is offline Offline
Light Poster

Compare 2 Tables - Return Rows VB 2008

 
0
  #1
Jun 2nd, 2008
Hows it going everyone. Im trying to compare two tables, and display the rows that are not in both tables in a DataGrid. Im using Visual Basic 2008, and created a query in the TableAdapterManager, but when I try to call the query, it is not displaying the results. Shows an error to lessen constraints, but I disabled constraints. I would really appreciate any tips, Im still pretty new to VB. Heres what I have in the query.

  1. SELECT Table1.Path, Table1.Filename, Table1.Type, Table1.[key], Table2.Path AS Expr1, Table2.Filename AS Expr2, Table2.Type AS Expr3
  2. FROM Table1, Table2
  3. WHERE (Table1.Path <> Table2.Path) OR
  4. (Table1.Filename <> Table2.Filename)
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 22
Reputation: dadelsen is an unknown quantity at this point 
Solved Threads: 5
dadelsen dadelsen is offline Offline
Newbie Poster

Re: Compare 2 Tables - Return Rows VB 2008

 
0
  #2
Jun 3rd, 2008
Do you want to
1) step throgh all rows of Table1, and show the row when there is no row with the same path AND filename in Table 2
2) and then do the same vice versa?

If yes, and DBMS is MS SQL Server or Oracle I would use a union:

  1. /* paste this in MS Query Analyzer, use || instead of + for oracle */
  2. DROP TABLE t1
  3. DROP TABLE t2
  4. CREATE TABLE t1(
  5. sPath VARCHAR(20),
  6. sFilename VARCHAR(10)
  7. )
  8. CREATE TABLE t2(
  9. sPath VARCHAR(20),
  10. sFilename VARCHAR(10)
  11. )
  12. INSERT INTO t1 VALUES ( 'P1', 'F1' )
  13. INSERT INTO t1 VALUES ( 'P2', 'F2' )
  14. INSERT INTO t2 VALUES ( 'P1', 'F1' )
  15. INSERT INTO t2 VALUES ( 'P3', 'F3' )
  16.  
  17. SELECT sPath + sFilename FROM t1 WHERE spath + sfilename NOT IN
  18. (SELECT spath + sfilename FROM t2)
  19. UNION ALL
  20. SELECT sPath + sFilename FROM t2 WHERE spath + sfilename NOT IN
  21. (SELECT spath + sfilename FROM t1)
  22.  
  23.  
  24. ------------------------------
  25. P2F2
  26. P3F3
  27. (2 rows affected)
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 45
Reputation: cellus205 is an unknown quantity at this point 
Solved Threads: 1
cellus205 cellus205 is offline Offline
Light Poster

Re: Compare 2 Tables - Return Rows VB 2008

 
0
  #3
Jun 3rd, 2008
Thanks a lot, that got it working for me. Just created the table with the query, databind, and there it was. Thanks again
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the VB.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC