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