当前位置: 首页>>代码示例>>C#>>正文


C# DataSet.MergeFailed事件代码示例

本文整理汇总了C#中System.Data.DataSet.MergeFailed事件的典型用法代码示例。如果您正苦于以下问题:C# DataSet.MergeFailed事件的具体用法?C# DataSet.MergeFailed怎么用?C# DataSet.MergeFailed使用的例子?那么恭喜您, 这里精选的事件代码示例或许可以为您提供帮助。您也可以进一步了解该事件所在System.Data.DataSet的用法示例。


在下文中一共展示了DataSet.MergeFailed事件的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DemonstrateMergeFailedEvent

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);
}
开发者ID:.NET开发者,项目名称:System.Data,代码行数:36,代码来源:DataSet.MergeFailed

示例2: Main

//引入命名空间
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;

public class MainClass {
  public static void Main(){
    OleDbConnection conn = new OleDbConnection();
    string strDSN = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Northwind.mdb";
    conn.ConnectionString = strDSN;
    conn.Open();

    string sql = "SELECT * FROM orders ";
    OleDbDataAdapter da = new OleDbDataAdapter(sql, conn);
    DataSet ds1 = new DataSet("ds1");
    da.Fill(ds1);

    sql = "SELECT * FROM Customers ";
    da = new OleDbDataAdapter(sql, conn);
    DataSet ds2 = new DataSet("ds2");
    da.Fill(ds2);

    ds1.MergeFailed += new MergeFailedEventHandler(OnMergeFailed);

    ds1.Merge(ds2);
  }

  protected static void OnMergeFailed  (object sender, MergeFailedEventArgs args)
  {
    MessageBox.Show(args.Conflict.ToString());
  }
}
开发者ID:C#程序员,项目名称:System.Data,代码行数:36,代码来源:DataSet.MergeFailed


注:本文中的System.Data.DataSet.MergeFailed事件示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。