G
Gene
I am having problems getting the MergeFailed event to fire using the
following code:
' Fill a DataSet with data from the pubs database
Dim dbConn As New
SqlClient.SqlConnection("server=localhost;uid=sa;pwd=;database=pubs")
Dim da As New SqlClient.SqlDataAdapter("SELECT au_id,
au_lname, au_fname, contract FROM authors", dbConn)
Dim ds As New DataSet("DS")
Dim ds2 As New DataSet("DS2")
' Fill with data and schema
da.Fill(ds)
' Only the schema for the other dataset
da.FillSchema(ds2, SchemaType.Source)
' Print the starting number of rows
Console.WriteLine("Starting number of rows: {0}",
ds.Tables(0).Rows.Count)
' Add a new row
Dim r As DataRow
r = ds2.Tables(0).NewRow()
r("au_id") = "172-32-1176"
r("au_fname") = "Fabio Claudio"
r("au_lname") = "Ferracchiata"
r("contract") = True
ds2.Tables(0).Rows.Add(r)
' Add the event handler to manage merge failures
AddHandler ds.MergeFailed, New
MergeFailedEventHandler(AddressOf OnMergeFailed)
' Merge the two DataSets
ds.Merge(ds2)
Private Sub OnMergeFailed(ByVal sender As Object, ByVal args As
MergeFailedEventArgs)
' Manage the errors here
Console.WriteLine("Merge failed for table " &
args.Table.TableName)
Console.WriteLine("Conflict = " & args.Conflict)
End Sub
The merge does fail since au_id = 172-32-1176 is already in the
authors table, but the OnMergeFailed() event handler is never called.
In the book "Microsoft ADO.NET Core Reference", David Sceppa, the
author, states "Personally, I've been unable to cause the MergeFailed
event to fire".
Is this a bug? Has anyone been able to get the MergeFailed event to
fire?
following code:
' Fill a DataSet with data from the pubs database
Dim dbConn As New
SqlClient.SqlConnection("server=localhost;uid=sa;pwd=;database=pubs")
Dim da As New SqlClient.SqlDataAdapter("SELECT au_id,
au_lname, au_fname, contract FROM authors", dbConn)
Dim ds As New DataSet("DS")
Dim ds2 As New DataSet("DS2")
' Fill with data and schema
da.Fill(ds)
' Only the schema for the other dataset
da.FillSchema(ds2, SchemaType.Source)
' Print the starting number of rows
Console.WriteLine("Starting number of rows: {0}",
ds.Tables(0).Rows.Count)
' Add a new row
Dim r As DataRow
r = ds2.Tables(0).NewRow()
r("au_id") = "172-32-1176"
r("au_fname") = "Fabio Claudio"
r("au_lname") = "Ferracchiata"
r("contract") = True
ds2.Tables(0).Rows.Add(r)
' Add the event handler to manage merge failures
AddHandler ds.MergeFailed, New
MergeFailedEventHandler(AddressOf OnMergeFailed)
' Merge the two DataSets
ds.Merge(ds2)
Private Sub OnMergeFailed(ByVal sender As Object, ByVal args As
MergeFailedEventArgs)
' Manage the errors here
Console.WriteLine("Merge failed for table " &
args.Table.TableName)
Console.WriteLine("Conflict = " & args.Conflict)
End Sub
The merge does fail since au_id = 172-32-1176 is already in the
authors table, but the OnMergeFailed() event handler is never called.
In the book "Microsoft ADO.NET Core Reference", David Sceppa, the
author, states "Personally, I've been unable to cause the MergeFailed
event to fire".
Is this a bug? Has anyone been able to get the MergeFailed event to
fire?