Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Filtering two datatables (urgent plz)

Filtering two datatables (urgent plz)

Scheduled Pinned Locked Moved Visual Basic
help
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    aamirsaddiq
    wrote on last edited by
    #1

    I have two datatables which are populating from two different tables of two different databases. I want to get all the records of first datatable which are not in 2nd datatable. I ‘m using the following piece of code. odr = oDs.Tables(0).Select("Sno = (SELECT SNO FROM " + Convert.ToString(oDataSetChanges.Tables(0)) + ")") or this one odr = oDs.Tables(0).Select("Sno NOT IN (SELECT " + Convert.ToString(oDataSetChanges.Tables(0).Columns("SNO")) + " FROM " + Convert.ToString(oDataSetChanges.Tables(0)) + ")") or I tried the following code as well oDv1.RowFilter = "Sno NOT IN (SELECT SNO FROM " + Convert.ToString(oDv2.Table) + ")" where SNO are the primary key columns of both tables but by using all these code I got the same syntax error that is Message "Syntax error: Missing operand after 'SNO' operator." Kindly help me in this reagard ASAP Thanx in advance

    M 1 Reply Last reply
    0
    • A aamirsaddiq

      I have two datatables which are populating from two different tables of two different databases. I want to get all the records of first datatable which are not in 2nd datatable. I ‘m using the following piece of code. odr = oDs.Tables(0).Select("Sno = (SELECT SNO FROM " + Convert.ToString(oDataSetChanges.Tables(0)) + ")") or this one odr = oDs.Tables(0).Select("Sno NOT IN (SELECT " + Convert.ToString(oDataSetChanges.Tables(0).Columns("SNO")) + " FROM " + Convert.ToString(oDataSetChanges.Tables(0)) + ")") or I tried the following code as well oDv1.RowFilter = "Sno NOT IN (SELECT SNO FROM " + Convert.ToString(oDv2.Table) + ")" where SNO are the primary key columns of both tables but by using all these code I got the same syntax error that is Message "Syntax error: Missing operand after 'SNO' operator." Kindly help me in this reagard ASAP Thanx in advance

      M Offline
      M Offline
      Mike Dimmick
      wrote on last edited by
      #2

      I don't think this is possible. The Select() method doesn't have the full power of SQL - it can only define fairly simple filter expressions. You can set up relations between tables in a DataSet with the Relations property to set up a parent/child table relationship; however, I don't think you'll be able to do this in this case - I don't think it'll help. I'd recommend - assuming that your data is coming from at least one SQL Server - setting up a link between the two servers (so that server A can see the table on server B) and performing the difference operation in a stored procedure. You can then use the full power of SQL. -- Mike Dimmick

      A 1 Reply Last reply
      0
      • M Mike Dimmick

        I don't think this is possible. The Select() method doesn't have the full power of SQL - it can only define fairly simple filter expressions. You can set up relations between tables in a DataSet with the Relations property to set up a parent/child table relationship; however, I don't think you'll be able to do this in this case - I don't think it'll help. I'd recommend - assuming that your data is coming from at least one SQL Server - setting up a link between the two servers (so that server A can see the table on server B) and performing the difference operation in a stored procedure. You can then use the full power of SQL. -- Mike Dimmick

        A Offline
        A Offline
        aamirsaddiq
        wrote on last edited by
        #3

        hi mike thanx for ur reply. i used ur opinion i.e linked both the sql servers via enterprise manager now tell me plz how much it will take effect on the execution performance with respect to time than that of disconnected datasets. regards Aamir

        M 1 Reply Last reply
        0
        • A aamirsaddiq

          hi mike thanx for ur reply. i used ur opinion i.e linked both the sql servers via enterprise manager now tell me plz how much it will take effect on the execution performance with respect to time than that of disconnected datasets. regards Aamir

          M Offline
          M Offline
          Mike Dimmick
          wrote on last edited by
          #4

          SQL Server uses OLE DB internally to access and manipulate tables of data. It's optimised for manipulating data sets. As long as the connection between the two servers is at least as fast as the connection between the client and the two servers, you shouldn't see any difference. Indeed it might even be quicker than two datasets, because SQL Server will tend to fetch rows from the linked database and its local database asynchronously, whereas you typically fill your local datasets synchronously, waiting for the first to complete before asking for the second. (I believe you could do this yourself by using BeginInvoke to perform both operations on the thread pool, then wait for both IAsyncResult.AsyncWaitHandles to be signalled). Your experience may vary and, as always with performance, you should measure it rather than guessing. Query Analyzer can show you the query execution plan and the time taken to execute the query. If the link between the servers is slow (perhaps they're located far apart, geographically?) you could consider replication instead.

          A 1 Reply Last reply
          0
          • M Mike Dimmick

            SQL Server uses OLE DB internally to access and manipulate tables of data. It's optimised for manipulating data sets. As long as the connection between the two servers is at least as fast as the connection between the client and the two servers, you shouldn't see any difference. Indeed it might even be quicker than two datasets, because SQL Server will tend to fetch rows from the linked database and its local database asynchronously, whereas you typically fill your local datasets synchronously, waiting for the first to complete before asking for the second. (I believe you could do this yourself by using BeginInvoke to perform both operations on the thread pool, then wait for both IAsyncResult.AsyncWaitHandles to be signalled). Your experience may vary and, as always with performance, you should measure it rather than guessing. Query Analyzer can show you the query execution plan and the time taken to execute the query. If the link between the servers is slow (perhaps they're located far apart, geographically?) you could consider replication instead.

            A Offline
            A Offline
            aamirsaddiq
            wrote on last edited by
            #5

            thnx for replying yes in my case the servers are far apart like for example one in US n other in SingaPore so can u tell me how i use replication as i have no idea of replication. i'll b very thankful to u regards aamir

            M 1 Reply Last reply
            0
            • A aamirsaddiq

              thnx for replying yes in my case the servers are far apart like for example one in US n other in SingaPore so can u tell me how i use replication as i have no idea of replication. i'll b very thankful to u regards aamir

              M Offline
              M Offline
              Mike Dimmick
              wrote on last edited by
              #6

              I could regurgitate a whole load of documentation here, but I won't: I'll just direct you to SQL Server Books Online[^] - note, this link is to a download, not online documentation. In the Contents tab, go to Replication. Snippet: When to Use Replication With organizations supporting diverse hardware and software applications in distributed environments, it becomes necessary to store data redundantly. Moreover, different applications have different needs for autonomy and data consistency. Replication is a solution for a distributed data environment when you need to:

              • Copy and distribute data to one or more sites.
              • Distribute copies of data on a scheduled basis.
              • Distribute data changes to other servers.
              • Allow multiple users and sites to make changes then merge the data modifications together, potentially identifying and resolving conflicts.
              • Build data applications that need to be used in online and offline environments.
              • Build Web applications where users can browse large volumes of data.
              • Optionally make changes at subscribing sites that are transparently under transactional control of the Publisher.

              If you always want the latest data available to your client, and cannot stand any stale data, stick with linked servers. Otherwise replication should produce less traffic between servers.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups