Freigeben über


DataSet.MergeFailed-Ereignis

Tritt auf, wenn eine Ziel- und eine Quell-DataRow denselben Primärschlüsselwert aufweisen und EnforceConstraints auf True festgelegt ist.

Namespace: System.Data
Assembly: System.Data (in system.data.dll)

Syntax

'Declaration
Public Event MergeFailed As MergeFailedEventHandler
'Usage
Dim instance As DataSet
Dim handler As MergeFailedEventHandler

AddHandler instance.MergeFailed, handler
public event MergeFailedEventHandler MergeFailed
public:
event MergeFailedEventHandler^ MergeFailed {
    void add (MergeFailedEventHandler^ value);
    void remove (MergeFailedEventHandler^ value);
}
/** @event */
public void add_MergeFailed (MergeFailedEventHandler value)

/** @event */
public void remove_MergeFailed (MergeFailedEventHandler value)
JScript unterstützt die Verwendung von Ereignissen, aber nicht die Deklaration von neuen Ereignissen.

Hinweise

Weitere Informationen zum Behandeln von Ereignissen finden Sie unter Behandeln von Ereignissen.

Beispiel

Das folgende Beispiel veranschaulicht die Verwendung des MergeFailed-Ereignisses.

Private Shared Sub DemonstrateMergeFailedEvent()
    ' Create a DataSet with one table containing two columns.
    Dim dataSet AS DataSet = New DataSet("dataSet")
    Dim table As DataTable = New DataTable("Items")
    
    ' Add table to the DataSet.
    dataSet.Tables.Add(table)

    ' Add two columns to the DataTable.
    table.Columns.Add("id", Type.GetType("System.Int32"))
    table.Columns.Add("item", Type.GetType("System.Int32"))

    ' Set the primary key to the first column.
    table.PrimaryKey = new DataColumn() { table.Columns("id") }

    ' Add MergeFailed event handler for the table.
    AddHandler dataSet.MergeFailed, _
        New MergeFailedEventHandler(AddressOf Merge_Failed)

    ' Create a second DataTable identical to the first, 
    Dim t2 As DataTable = table.Clone()

    ' Set the primary key of the new table to the second column.
    ' This will cause the MergeFailed event to be raised when the
    ' table is merged into the DataSet.
    t2.PrimaryKey = New DataColumn() { t2.Columns("item") }
    
    ' Merge table into the DataSet.
    Console.WriteLine("Merging...")
    dataSet.Merge(t2, false, MissingSchemaAction.Add)
End Sub

Private Shared Sub Merge_Failed(sender As object, _
    e As MergeFailedEventArgs)
    Console.WriteLine("Merge_Failed Event: '{0}'", e.Conflict)
End Sub
private static void DemonstrateMergeFailedEvent()
{
    // Create a DataSet with one table containing two columns.
    DataSet dataSet = new DataSet("dataSet");
    DataTable table = new DataTable("Items");

    // Add table to the DataSet.
    dataSet.Tables.Add(table);

    // Add two columns to the DataTable.
    table.Columns.Add("id", typeof(int));
    table.Columns.Add("item", typeof(int));

    // Set the primary key to the first column.
    table.PrimaryKey = new DataColumn[] { table.Columns["id"] };

    // Add MergeFailed event handler for the table.
    dataSet.MergeFailed += new MergeFailedEventHandler(Merge_Failed);

    // Create a second DataTable identical to the first, 
    DataTable t2 = table.Clone();

    // Set the primary key of the new table to the second column.
    // This will cause the MergeFailed event to be raised when the
    // table is merged into the DataSet.
    t2.PrimaryKey = new DataColumn[] { t2.Columns["item"] };

    // Merge the table into the DataSet.
    Console.WriteLine("Merging...");
    dataSet.Merge(t2, false, MissingSchemaAction.Add);
}

private static void Merge_Failed(object sender, MergeFailedEventArgs e)
{
    Console.WriteLine("Merge_Failed Event: '{0}'", e.Conflict);
}

Plattformen

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

.NET Compact Framework

Unterstützt in: 2.0

Siehe auch

Referenz

DataSet-Klasse
DataSet-Member
System.Data-Namespace

Weitere Ressourcen

Verwenden von DataSets in ADO.NET