473,320 Members | 2,088 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

AcceptChanges() woes :(

153 100+
Friends !
How are u doing today ?

Now coming to the point :)

According to MSDN

Changes to a DataTable are not final until you call the AcceptChanges method. When either AcceptChanges or RejectChanges is called on a row in the parent table, the AcceptRejectRule value determines whether or not changes are propagated to corresponding rows in the child table.

Here goes my code:
Expand|Select|Wrap|Line Numbers
  1.     public partial class Form1 : Form
  2.     {
  3.         DataSet Childhood;
  4.         DataTable parentTable;
  5.         DataTable childTable;
  6.         ForeignKeyConstraint FKC;
  7.  
  8.         public Form1()
  9.         {
  10.             InitializeComponent();
  11.         }
  12.  
  13.         private void btnconnect_Click(object sender, EventArgs e)
  14.         {
  15.             parentTable = new DataTable("ParentTable");
  16.             parentTable.Columns.Add("ParentID", typeof(int));
  17.             parentTable.Columns["ParentID"].AutoIncrement = true;
  18.             parentTable.Columns["ParentID"].AutoIncrementSeed = 1;
  19.             parentTable.Columns.Add("ParentName", typeof(string));
  20.  
  21.  
  22.             childTable = new DataTable("ChildTable");
  23.             childTable.Columns.Add("ChildID", typeof(int));
  24.             childTable.Columns["ChildID"].AutoIncrement = true;
  25.             childTable.Columns["ChildID"].AutoIncrementSeed = 1;
  26.             childTable.Columns.Add("ParentID", typeof(int));
  27.             childTable.Columns.Add("ChildName", typeof(string));
  28.  
  29.             Childhood = new DataSet();
  30.             Childhood.Tables.Add(parentTable);
  31.             Childhood.Tables.Add(childTable);
  32.  
  33.  
  34.             FKC = new ForeignKeyConstraint("ForeignKey", parentTable.Columns["ParentID"], childTable.Columns["ParentID"]);
  35.             FKC.UpdateRule = Rule.Cascade;
  36.             FKC.DeleteRule = Rule.Cascade;
  37.             childTable.Constraints.Add(FKC);
  38.             Childhood.EnforceConstraints = true;
  39.  
  40.             dataGridView1.DataSource = parentTable;
  41.             dataGridView2.DataSource = childTable; 
  42.         }
  43.  
  44.         private void btnacceptchanges_Click(object sender, EventArgs e)
  45.         {
  46.             parentTable.AcceptChanges();
  47.         }
  48.  
  49.         private void btncascade_Click(object sender, EventArgs e)
  50.         {
  51.             FKC.AcceptRejectRule = AcceptRejectRule.Cascade;
  52.         }
  53.  
  54.         private void btnnone_Click(object sender, EventArgs e)
  55.         {
  56.             FKC.AcceptRejectRule = AcceptRejectRule.None;
  57.         }
  58.  
  59.         private void btnrejectchanges_Click(object sender, EventArgs e)
  60.         {
  61.             parentTable.RejectChanges();
  62.         }
  63.  
  64.     }
In the above code when the btnconenct's is clicked the two datagridview(s) get their data sources(the two DataTables).

Also I create one parent(in parent table) and create 3 children(in child table) of it.

I click on btnnone to make AcceptRejectRule = AcceptRejectRule.None

now i change the parent ID of the parent and subsequently the child rows are affected(as per the ForeignKeyConstraint ).

Now since I had set AcceptRejectRule = AcceptRejectRule.None I expected that when i click btnacceptchanges the parent row and the child rows would revert back to their original value.

But sadly it does not happen.

The changes get saved !

Now where am i mistaken ???


Thanks !
Sep 18 '08 #1
2 1244
akshaycjoshi
153 100+
just wrote this to bring the question on the top of the queue ;)
Sep 19 '08 #2
Plater
7,872 Expert 4TB
I would think that AcceptRejectRule.None would mean that EVERYTHING would be accepted?
Sep 19 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Allan Bredahl | last post by:
Hi All I have a problem with getting a DataTable to submit changes back to the database when calling AcceptChanges. What I do is simplyfied this : 1) I set up a SqlDataAdapter with...
0
by: Steve Amey | last post by:
Hi all I have a form with some data bound to it. There is a list on the form that could display any number of records that the user requests. When changes are made to the data I use the...
4
by: Christopher Weaver | last post by:
I can't get this method to work as I expect it to. If I edit a row within a DataSet, then invoke the DA's Update, the changes to the current row are lost. If I move off the modified row then...
1
by: Johann Blake | last post by:
I'm not sure that I entirely understand the purpose of the AcceptChanges methon in a DataView. I added a new record to a DataView and noticed that its RowState indicated it as being "Added". If I...
2
by: pushpendra vats | last post by:
Hi!!, I have created a dataadapter and datasdet through code .On button i have added two records in dataset and called acceptchanges method. on second button i am inserting the records in...
10
by: jaYPee | last post by:
does anyone experienced slowness when updating a dataset using AcceptChanges? when calling this code it takes many seconds to update the database SqlDataAdapter1.Update(DsStudentCourse1)...
2
by: Niels Jensen | last post by:
I have a some code which imports information from a text file to a dataset. Depending op what is being extracted from the text file, the dataset has 5 tables which can be written to. During this...
3
by: Ryan Liu | last post by:
Hi, In the .NET Framework SDK documentation, I can see DataRow.AcceptChanges method will throw RowNotInTableException exeception. And in DataTable.AcceptChanges(), the documentation does not...
1
by: Andy B | last post by:
I have the following code: //delete the row in the table that has ID of 1. This line works fine. DataSet.Table.Rows.Find(1).Delete(); //Accept the delete changes to the table. This row returns...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.