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. C#
  4. How to Compare the two database tables(table1,Table2) and update the difference into (table2) using c#

How to Compare the two database tables(table1,Table2) and update the difference into (table2) using c#

Scheduled Pinned Locked Moved C#
csharpdatabasedesignsecurityhelp
1 Posts 1 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.
  • B Offline
    B Offline
    bruze
    wrote on last edited by
    #1

    Can any one Help I am trying Compare the two database tables(table1,Table2) and update the difference into (table2) using c#. I have Compared two tables and got the difference value. How to update the difference value into table2 particular row? Student.aspx ************* In aspx page I have added the three Gridview

    Student.aspx.cs
    ********************
    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Data.SqlClient;

    public partial class Student : System.Web.UI.Page
    {
    Comapre objComapre = new Comapre();
    protected void Page_Load(object sender, EventArgs e)
    {
    DataTable First=new DataTable();
    DataTable Second = new DataTable();
    DataTable Compare = new DataTable();

      First = objComapre.GetStudentTableOne();
      Second = objComapre.GetStudentTableTwo();
      Compare=compareDataTables(First, Second);
    
      GridView1.DataSource = First;
      GridView1.DataBind();
      GridView2.DataSource = Second;
      GridView2.DataBind();
      GridView3.DataSource = Compare;
      GridView3.DataBind();
    }
    
    public DataTable compareDataTables(DataTable First, DataTable Second)
    {
        First.TableName = "FirstTable";
        Second.TableName = "SecondTable";
    
        //Create Empty Table
        DataTable table = new DataTable("Difference");
    
        try
        {
            //Must use a Dataset to make use of a DataRelation object
            using (DataSet ds = new DataSet())
            {
                //Add tables
                ds.Tables.AddRange(new DataTable\[\] { First.Copy(), Second.Copy() });
    
                //Get Columns for DataRelation
                DataColumn\[\] firstcolumns = new DataColumn\[ds.Tables\[0\].Columns.Count\];
    
                for (int i = 0; i < firstcolumns.Length; i++)
                {
                    firstcolumns\[i\] = ds.Tables\[0\].Columns\[i\];
                }
    
                DataColumn\[\] secondcolumns = new DataColumn\[ds.Tables\[1\].Columns.Count\];
    
                for (int i = 0; i < secondcolumns.Length; i++)
                {
                    secondcolumns\[i\] = ds.Tables\[1\].Columns\[i\];
                }
    
                //Create DataRelation
                DataRelation r = new DataRelation(string.Empty, first
    
    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