943,671 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Marked Solved
  • Views: 3480
  • VB.NET RSS
Jun 2nd, 2008
0

Compare 2 Tables - Return Rows VB 2008

Expand Post »
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.

VB.NET Syntax (Toggle Plain Text)
  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)
Reputation Points: 10
Solved Threads: 3
Junior Poster in Training
cellus205 is offline Offline
57 posts
since May 2007
Jun 3rd, 2008
0

Re: Compare 2 Tables - Return Rows VB 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:

VB.NET Syntax (Toggle Plain Text)
  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)
Reputation Points: 25
Solved Threads: 5
Newbie Poster
dadelsen is offline Offline
22 posts
since Jun 2007
Jun 3rd, 2008
0

Re: Compare 2 Tables - Return Rows VB 2008

Thanks a lot, that got it working for me. Just created the table with the query, databind, and there it was. Thanks again
Reputation Points: 10
Solved Threads: 3
Junior Poster in Training
cellus205 is offline Offline
57 posts
since May 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: enter key
Next Thread in VB.NET Forum Timeline: Help StreamReader with DataGrid XML





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC