RE: Constraint violated but no exception thrown
From: davisonm (davisonm_at_discussions.microsoft.com)
Date: 01/06/05
- Next message: Patrice: "Re: Is TDS used only if server is local?"
- Previous message: MrDotNet: "Re: How Get Paramenter information in Stored Procedure (DataType,N"
- In reply to: davisonm: "Constraint violated but no exception thrown"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 6 Jan 2005 10:01:02 -0800
Just to wrap up the thread I started, and describe the solution...
I had a RowUpdated event handler on my DataAdapter with just three lines of
code:
If e.StatementType = StatementType.Insert Then
e.Status = UpdateStatus.SkipCurrentRow
End If
Problem was that e.Status has multiple functions. When an error occurs it
contains the enumeration value ErrorsOccurred. That's how you know that
Something Bad happened (SB error). But, to have the error throw an
exception, it's necessary to _exit_ the handler with e.Status set to
ErrorsOccurred. When I unconditionally changed e.Status to SkipCurrentRow
(at least for all inserts), that "turned off" all exceptions thrown by the
call to DataAdapter.Update. So now the handler is:
If (e.StatementType = StatementType.Insert AndAlso e.Status =
UpdateStatus.Continue) Then
e.Status = UpdateStatus.SkipCurrentRow
End If
Which works just right! And so it goes...
"davisonm" wrote:
> I have a VB Windows form that calls the DataAdapter.Update method, passing a
> DataTable of one row with RowState = 'Added'. This is the stripped-down code:
>
> Try
> Dim Count As Integer = MySqlAdapter.Update(MyDataTable.GetChanges)
> Catch ex As System.Data.SqlClient.SqlException
> MessageBox.Show("Update failed: " & ex.Message)
> End Try
>
> The underlying table, in SQL Server 2000, has a unique constraint defined on
> a non-PK data column. When that column has a DataTable value which violates
> the constraint, the DB refuses to add the row, Update returns zero for a
> rowcount, but there is no exception thrown.
>
> Why not?
>
> Client: Windows XP SP1, Visual Studio 2003 version 7.1.3088, .NET Framework
> 1.1 version 1.1.4322 SP1, MDAC 2.8 RTM
> Server: Windows NT 5.0 (Build 2195: Service Pack 2), SQL Server 2000 version
> 8.00.760
>
- Next message: Patrice: "Re: Is TDS used only if server is local?"
- Previous message: MrDotNet: "Re: How Get Paramenter information in Stored Procedure (DataType,N"
- In reply to: davisonm: "Constraint violated but no exception thrown"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|