本文整理汇总了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);
}
示例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());
}
}