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 swaim@hal-pc.org at home | Quote: "Boingie"^4 Y,W & D
MD Anderson Dept. of Biostatistics & Applied Mathematics
mpswaim@mdanderson.org or mswaim@odin.mdacc.tmc.edu at work
Disclaimer: Yeah, like I speak for MD Anderson.

Re: Copying Data from one DB to another. by Erik

Erik
Fri May 14 15:42:29 CDT 2004

"Mike Swaim" <mswaim@odin.mdacc.tmc.edu> wrote in message
news:uFAvwkeOEHA.624@TK2MSFTNGP11.phx.gbl...
>
> 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 swaim@hal-pc.org at home | Quote: "Boingie"^4 Y,W & D
> MD Anderson Dept. of Biostatistics & Applied Mathematics
> mpswaim@mdanderson.org or mswaim@odin.mdacc.tmc.edu 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



Re: Copying Data from one DB to another. by Miha

Miha
Fri May 14 15:46:07 CDT 2004

Hi Mike,

Try using adapter.RowUpdating event.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

"Mike Swaim" <mswaim@odin.mdacc.tmc.edu> wrote in message
news:uFAvwkeOEHA.624@TK2MSFTNGP11.phx.gbl...
>
> 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 swaim@hal-pc.org at home | Quote: "Boingie"^4 Y,W & D
> MD Anderson Dept. of Biostatistics & Applied Mathematics
> mpswaim@mdanderson.org or mswaim@odin.mdacc.tmc.edu at work
> Disclaimer: Yeah, like I speak for MD Anderson.
>



Re: Copying Data from one DB to another. by Mike

Mike
Mon May 17 13:12:14 CDT 2004

Erik Frey wrote:

> 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.

--
Mike Swaim swaim@hal-pc.org at home | Quote: "Boingie"^4 Y,W & D
MD Anderson Dept. of Biostatistics & Applied Mathematics
mpswaim@mdanderson.org or mswaim@odin.mdacc.tmc.edu at work
Disclaimer: Yeah, like I speak for MD Anderson.