Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

DataTable.GetChanges()

$
0
0

Hello there,

I am having two data tables and trying to merge it to get the updated rows alone.

DataTable dt = new DataTable();
                DataColumn dc1 = new DataColumn("CaseID", typeof(System.Int32));
                dt.Columns.Add(dc1);
                dt.Columns.Add("AEGISID");
                dt.Columns.Add("VersionNo");

                DataRow dr = dt.NewRow();
                dr["CaseID"] = 123;
                dr["AEGISID"] = "ABC";
                dr["VersionNo"] = "1";
                dt.Rows.Add(dr);

                DataRow dr2 = dt.NewRow();
                dr2["CaseID"] = 124;
                dr2["AEGISID"] = "ABC";
                dr2["VersionNo"] = "2";
                dt.Rows.Add(dr2);

                dt.PrimaryKey = new DataColumn[] { dc1 };

                DataTable dt2 = dt.Clone();
                
                DataRow dr21 = dt2.NewRow();
                dr21["CaseID"] = 123;
                dr21["AEGISID"] = "ABC";
                dr21["VersionNo"] = "12";
                dt2.Rows.Add(dr21);

                DataRow dr22 = dt2.NewRow();
                dr22["CaseID"] = 124;
                dr22["AEGISID"] = "ABC";
                dr22["VersionNo"] = "2";
                dt2.Rows.Add(dr22);

                DataTable dtCopy = dt.Copy();                

                dtCopy.AcceptChanges();
                dtCopy.Merge(dt2);

                DataTable dtModified = dtCopy.GetChanges(DataRowState.Modified);
                
                DataTable dtUnChanged = dtCopy.GetChanges(DataRowState.Unchanged);

In the dtModified - I am getting both the rows but the expected one is 123

In the dtUnChanged - null but the expected on is 124

Is there a way to overcome this?

At least to remove the unchanged row from the table dt.

Appreciate on any help

Thanks.


Viewing all articles
Browse latest Browse all 2535

Trending Articles