Duplicate insert problem

S

Sam

When using a datagrid on a simple form I get another entry that is exaclty
the same to be inserted. The actual database values are correct (no
duplication). Why is the datagrid showing me two of the same records even if
the database has one correct insert. It is driving me insane. I checked the
following:

I checked my insertcommand statement and it is working exaclty like a new
dataform that I created which is functioning correctly.
I checked the ds object and dataadapter objects' properties and the form
that works with the table has the same properties.


If I refresh or reload the dataset the datagrid shows everything correctly.
Its only when I run the following that the duplication shows in the
datagrid. And again I noticed this wasn't happening on a form that I newly
created using the wizard ( I basically modified my version for checking rows
and other stuff)


if ((objDataSetChanges != null))
{
try
{
// There are changes that need to be made, so attempt to update the
datasource by
// calling the update method and passing the dataset and any parameters.
if (MessageBox.Show("Do you want to save the changes?", "Save Changes",
MessageBoxButtons.YesNo ) == DialogResult.Yes)
{
this.UpdateDataSource(objDataSetChanges);
objdsTimesheet.Merge(objDataSetChanges);
objdsTimesheet.AcceptChanges();
}
}
catch (System.Exception eUpdate)
{
// Add your error handling code here.
throw eUpdate;
}
// Add your code to check the returned dataset for any errors that may have
been
// pushed into the row object's error.
}
 
M

Marina

Do you have the primary key defined correctly on the table? It looks like it
isn't, so the merge thinks the rows are different.
 
B

Bart Mermuys

Hi,

Sam said:
When using a datagrid on a simple form I get another entry that is exaclty
the same to be inserted. The actual database values are correct (no
duplication). Why is the datagrid showing me two of the same records even
if
the database has one correct insert. It is driving me insane. I checked
the
following:

There is a problem if you use an insert query that also retrieves the
autogenerated key from the DB and the update sequence you use : GetChanges,
Update, Merge.

See http://support.microsoft.com/default.aspx?scid=kb;en-us;313540
In particular the solution about adding an eventhandler to the RowUpdated
event of the DataAdapter.

HTH,
Greetings
 
S

Sam

If I understand correctly you mean if I have primary key defined or not. I
made sure to check it and yes it is defined. The issue is the form works
when I create a new dataform. I'm trying to figure out what could of
changed from my custom modifications of that form. Is it possible that
changing the select statement to be filtered can cause this.


Thanks Marina
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top