472,982 Members | 1,310 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

"DataSet.Merge()" simple problem

Hi there,

Can anyone explain the following (very) simple scenario.

1) I make an exact copy of my "DataSet" and delete one record from a given
table (in the copy)
2) I invoke "DataSet.GetChanges()" on the above copy and pass the results to
"DataSet.Merge()" on the original copy
3) If I now inspect the original copy, it shows that the record has *not*
been deleted from the table. However, a call to "GetChanges()" does show my
deleted record.

Why doesn't the record get deleted from the original table after the merge
in step 2? Note that I've inspected my original "DataSet" after step 2 as
well as the "DataSet" returned by "DataSet.GetChanges()". Apparently
"DataSet.GetChanges()" returns a "DataSet" that's completely empty of data
except for the one affected table which contains the single deleted record.
That record is then simply added to the table in the original "DataSet" when
"DataSet.Merge()" is called. The original table therefore winds up with two
copies of the record, the origiinal and the deleted. Does anyone know what's
going on here. Thanks in advance.
May 19 '07 #1
5 16638
Hi,
I am not entirely sure if i had grasped your query correctly.I have written
a code snippet in C# Windows App and it is working perfectly well.

DataSet ds1 = new DataSet();
DataTable dt1 = new DataTable();
dt1.Columns.Add("ID", typeof(int));

DataRow dr1 = dt1.NewRow();
dr1[0] = 1;
dt1.Rows.Add(dr1);

DataRow dr2 = dt1.NewRow();
dr2[0] = 2;
dt1.Rows.Add(dr2);

ds1.Tables.Add(dt1);

ds1.Tables[0].Rows.RemoveAt(0);

DataSet ds2 = new DataSet();

ds2 = ds1.GetChanges();

ds1.AcceptChanges();

ds1.Merge(ds2);

MessageBox.Show(ds1.Tables[0].Rows.Count.ToString());
please do let me know if this is what you are trying to do.
--
Thanks and Regards.
Manish Bafna.
MCP and MCTS.

"Mark Chambers" wrote:
Hi there,

Can anyone explain the following (very) simple scenario.

1) I make an exact copy of my "DataSet" and delete one record from a given
table (in the copy)
2) I invoke "DataSet.GetChanges()" on the above copy and pass the results to
"DataSet.Merge()" on the original copy
3) If I now inspect the original copy, it shows that the record has *not*
been deleted from the table. However, a call to "GetChanges()" does show my
deleted record.

Why doesn't the record get deleted from the original table after the merge
in step 2? Note that I've inspected my original "DataSet" after step 2 as
well as the "DataSet" returned by "DataSet.GetChanges()". Apparently
"DataSet.GetChanges()" returns a "DataSet" that's completely empty of data
except for the one affected table which contains the single deleted record.
That record is then simply added to the table in the original "DataSet" when
"DataSet.Merge()" is called. The original table therefore winds up with two
copies of the record, the origiinal and the deleted. Does anyone know what's
going on here. Thanks in advance.
May 19 '07 #2
Thanks for the feedback. Try this instead:

///////////////////////////////////////////////////
DataSet ds1 = new DataSet();
DataTable dt1 = new DataTable();
dt1.Columns.Add("ID", typeof(int));

DataRow dr1 = dt1.NewRow();
dr1[0] = 1;
dt1.Rows.Add(dr1);

DataRow dr2 = dt1.NewRow();
dr2[0] = 2;
dt1.Rows.Add(dr2);

ds1.Tables.Add(dt1);
ds1.AcceptChanges();

DataSet ds2 = ds1.Copy();
ds2.Tables[0].Rows[0].Delete(); // Delete ID 1

DataSet ds3 = ds2.GetChanges();
ds1.Merge(ds3);
///////////////////////////////////////////////////

After the merge, "ds1" contains the original (unaltered) rows plus one extra
(deleted) row with ID 1. Shouldn't the original row with ID 1 simply be
deleted instead?
May 19 '07 #3
Mark,

I miss the primary key in your tables?

Cor

"Mark Chambers" <no_spam@_nospam.comschreef in bericht
news:OQ****************@TK2MSFTNGP03.phx.gbl...
Thanks for the feedback. Try this instead:

///////////////////////////////////////////////////
DataSet ds1 = new DataSet();
DataTable dt1 = new DataTable();
dt1.Columns.Add("ID", typeof(int));

DataRow dr1 = dt1.NewRow();
dr1[0] = 1;
dt1.Rows.Add(dr1);

DataRow dr2 = dt1.NewRow();
dr2[0] = 2;
dt1.Rows.Add(dr2);

ds1.Tables.Add(dt1);
ds1.AcceptChanges();

DataSet ds2 = ds1.Copy();
ds2.Tables[0].Rows[0].Delete(); // Delete ID 1

DataSet ds3 = ds2.GetChanges();
ds1.Merge(ds3);
///////////////////////////////////////////////////

After the merge, "ds1" contains the original (unaltered) rows plus one
extra (deleted) row with ID 1. Shouldn't the original row with ID 1 simply
be deleted instead?

May 19 '07 #4
I miss the primary key in your tables?

Hmmm, very strange. When I add the primary key to this example (forget it
the first time - thanks) it works fine. In my own code however the primary
keys are there but it doesn't work. This problem is almost identical to
another one I just found here (by a C# MVP):

http://forums.microsoft.com/MSDN/Sho...32312&SiteID=1

I'll have to play around with this some more to figure out what's going on.
It seems like there's a possible MSFT bug somewhere.
May 19 '07 #5
>I miss the primary key in your tables?
>
Hmmm, very strange. When I add the primary key to this example (forget it
the first time - thanks) it works fine. In my own code however the primary
keys are there but it doesn't work. This problem is almost identical to
another one I just found here (by a C# MVP):

http://forums.microsoft.com/MSDN/Sho...32312&SiteID=1

I'll have to play around with this some more to figure out what's going
on. It seems like there's a possible MSFT bug somewhere.
Ok, thanks for each of your help. It was the primary key after all. The
designer apparently reset it in one of my tables without my knowledge. None
of these keys have been touched by me in ages however but the designer isn't
always stable and does things like this from time-to-time (as an example,
the forms designer frequently sets "Forms.CancelButton" back to null for no
apparent reason). Anyway, thanks again (appreciated).
May 19 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Nick | last post by:
excuse me!! may i ask a simple problem here? if i dynamically allocate a memory(ex. new in C++ or malloc in C) in a sub-function and forget free the space end of the sub-function. does it...
1
by: newbie001 | last post by:
I have the following code in a listview control's initList function (called from form_load event). i can't understand why the listview box still appears blank with no columns or listview items. ...
3
by: Mark Allison | last post by:
Hi, VERY simple problem! if (regServer.UseTrustedConnection == 1) { string connectionString = "server=" + regServer.Name + "; Trusted_Connection=yes; database=master"; } else
18
by: Sender | last post by:
Yesterday there was a very long thread on this query. (You can search on this by post by 'sender' with subject 'Simple Problem' post date Oct 7 time 1:43p) And in the end the following code was...
12
by: Peter Proost | last post by:
Hi group, I've got what seems a simple problem, but I can't find the solution. I've got a textbox and a handheld scanner to scan barcodes, the scanner just generates keypresses like a keyboard...
2
by: Simon Harvey | last post by:
Hi everyone, I'm having a really simple problem - I can't seem to insert a null value into the database. When I do it tells me that the procedure expects the parameter and that I'm not providing...
4
by: R.A.M. | last post by:
Hi I have very simple problem - I need to process asp:Button click at server. I have written (my experience is little) in .aspx: <asp:Button ID="GoTo" runat="server" Text="Go To"...
8
by: rdrink | last post by:
I am just getting into pysqlite (with a fair amount of Python and MySQL experience behind me) and have coded a simple test case to try to get the hang of things... yet have run into a 'stock...
7
by: axlq | last post by:
I know this is a simple problem but it bedevils me. I'd like to have a container with two columns with the following properties: 1. Both columns dynamically adjust their width to fit their...
6
by: Gun Slinger | last post by:
Hi guys, I have a simple problem which i cant seem to figure out. Im not sure if its my fault, or just VS2008.. I have a group box, which i change its name to show a user that the contents of the...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.