Results 1 to 5 of 5

Thread: DataTable Comparision

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2007
    Posts
    14

    DataTable Comparision

    Hello All,

    I am working in C#.NET 2.0
    I need to Compare two databases, in which one is of Oracle Database and another is of SQL Server 2000 database. I want to delete records from SQL Serever which are not in Oracle database.

    I created two datatables - SQLdt and ORAdt,I did upto filling these two datatables using Query but i dont know how to compare two datatables.

    Can anyone help me to solve this?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: DataTable Comparision

    How are you identifying that rows are the same? Must they have all fields match? ...just an ID? ...some other field or fields?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2007
    Posts
    14

    Re: DataTable Comparision

    Thank you for yr reply...

    I have a common field - ID - in both DataTables but i dont know how to compare two rows of different DataTables

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: DataTable Comparision

    Presumably that column is the primary key. In that case you can do this:
    C# Code:
    1. DataRow row2;
    2.  
    3. foreach (DataRow row1 in table1)
    4. {
    5.     row2 = table2.Rows.Find(row1("ID"));
    6.  
    7.     if (row2 != null)
    8.     {
    9.         // A matching ID was found.
    10.     }
    11. }
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5
    Registered User RaviIntegra's Avatar
    Join Date
    Mar 2007
    Location
    Pondicherry, India
    Posts
    125

    Re: DataTable Comparision

    Try to bind 2 tables ID's in 2 comboboxe and then you can easily compare both the combobox.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width