Copying Data from one DB to another.

  • Thread starter Thread starter Mike Swaim
  • Start date Start date
M

Mike Swaim

I'm using the DataSet merge and DataAdpater Update functions to copy
data from a table in one database to another. It works just fine,
except when it doesn't. Occasionally I'll get an error in the target
database because one of its constraints is being violated, and my
application will throw an exception.
How do I trap this exception, and determine what values were being
inserted/updated when it was thrown?
 
Mike Swaim said:
I'm using the DataSet merge and DataAdpater Update functions to copy
data from a table in one database to another. It works just fine,
except when it doesn't. Occasionally I'll get an error in the target
database because one of its constraints is being violated, and my
application will throw an exception.
How do I trap this exception, and determine what values were being
inserted/updated when it was thrown?

--
Mike Swaim (e-mail address removed) at home | Quote: "Boingie"^4 Y,W & D
MD Anderson Dept. of Biostatistics & Applied Mathematics
(e-mail address removed) or (e-mail address removed) at work
Disclaimer: Yeah, like I speak for MD Anderson.

Besides catching an SqlException (or ODBCException or whatever you may be
using) around the Update method itself, you can also handle the RowUpdated
event of the DataAdapter.

In the docs, you will see two fields of use in the event args for that
event - Status and Row. So you can do something like this:

private void DataAdapter_RowUpdated(object sender,
System.Data.SqlClient.SqlRowUpdatedEventArgs e)
{
if (e.Status == System.Data.UpdateStatus.ErrorsOccurred)
MessageBox.Show(e.Row["ID"]);
}

Erik
 
Erik said:
Besides catching an SqlException (or ODBCException or whatever you
may be using) around the Update method itself, you can also handle
the RowUpdated event of the DataAdapter.

In the docs, you will see two fields of use in the event args for that
event - Status and Row. So you can do something like this:

private void DataAdapter_RowUpdated(object sender,
System.Data.SqlClient.SqlRowUpdatedEventArgs e)
{
if (e.Status == System.Data.UpdateStatus.ErrorsOccurred)
MessageBox.Show(e.Row["ID"]);
}

Thanks. That did it.
 
Back
Top