DataTable.Merge 方法 (DataTable)
2013-02-25 13:37
169 查看
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace chxboxs
{
public partial class Form1 : Form
{
private DataTable table1;
private void Form1_Load(object sender, EventArgs e)
{
table1 = new DataTable("Items");
// Add columns
DataColumn column1 = new DataColumn("id", typeof(System.Int32));
DataColumn column2 = new DataColumn("item", typeof(System.Int32));
table1.Columns.Add(column1);
table1.Columns.Add(column2);
// Set the primary key column.
table1.PrimaryKey = new DataColumn[] { column1 };
// Add some rows.
DataRow row;
for (int i = 0; i <=2; i++)
{
row = table1.NewRow();
row["id"] = i;
row["item"] = i;
table1.Rows.Add(row);
}
// Accept changes.
table1.AcceptChanges();
//PrintValues(table1, "Original values");
this.dataGridView2.DataSource = table1;
// Create a second DataTable identical to the first.
}
private void button2_Click(object sender, EventArgs e)
{
DataTable table2 = table1.Clone();
DataRow row;
row = table2.NewRow();
row["id"] = 14;
row["item"] = 774;
table2.Rows.Add(row);
row = table2.NewRow();
row["id"] = 12;
row["item"] = 555;
table2.Rows.Add(row);
table1.Merge(table2);
this.dataGridView2.DataSource = table1;
}
private Form2 f2;
public Form1()
{
InitializeComponent();
}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
this.label1.Text = e.KeyCode.ToString();
}
private void button1_Click(object sender, EventArgs e)
{
if (f2 == null||f2.IsDisposed)
{
f2 = new Form2();
f2.Show();
}
else
{
f2.Activate();
}
}
}
}
将指定的 DataTable 与当前的 DataTable 合并。
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace chxboxs
{
public partial class Form1 : Form
{
private DataTable table1;
private void Form1_Load(object sender, EventArgs e)
{
table1 = new DataTable("Items");
// Add columns
DataColumn column1 = new DataColumn("id", typeof(System.Int32));
DataColumn column2 = new DataColumn("item", typeof(System.Int32));
table1.Columns.Add(column1);
table1.Columns.Add(column2);
// Set the primary key column.
table1.PrimaryKey = new DataColumn[] { column1 };
// Add some rows.
DataRow row;
for (int i = 0; i <=2; i++)
{
row = table1.NewRow();
row["id"] = i;
row["item"] = i;
table1.Rows.Add(row);
}
// Accept changes.
table1.AcceptChanges();
//PrintValues(table1, "Original values");
this.dataGridView2.DataSource = table1;
// Create a second DataTable identical to the first.
}
private void button2_Click(object sender, EventArgs e)
{
DataTable table2 = table1.Clone();
DataRow row;
row = table2.NewRow();
row["id"] = 14;
row["item"] = 774;
table2.Rows.Add(row);
row = table2.NewRow();
row["id"] = 12;
row["item"] = 555;
table2.Rows.Add(row);
table1.Merge(table2);
this.dataGridView2.DataSource = table1;
}
private Form2 f2;
public Form1()
{
InitializeComponent();
}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
this.label1.Text = e.KeyCode.ToString();
}
private void button1_Click(object sender, EventArgs e)
{
if (f2 == null||f2.IsDisposed)
{
f2 = new Form2();
f2.Show();
}
else
{
f2.Activate();
}
}
}
}
将指定的 DataTable 与当前的 DataTable 合并。
相关文章推荐
- DataTable对象Merge方法
- DataTable.Merge()方法
- DataTable.Merge()方法
- 将两个DataTable合并——DataTable.Merge 方法
- 利用关键字拼接两个Datatable。方法名:DataTable.Merge
- DataTable.Merge 方法 (DataTable)
- 将有数据的datatable存入dataset (DataSet.Merge 方法)
- DataTable的Merge方法和添加datatable到dataset
- DataTable的Merge方法和添加datatable到dataset
- ASP.NET DataTable添加行的方法
- 遍历DataTable内存数据的三种方法性能对比
- DataTable.OnRowChanged 方法
- DataTable.Compute 方法 记录一下
- DataTable的4个方法小结--Select,Clone,Copy,ImportRow
- C# 将DataTable表中的数据批量插入到数据库表中的方法
- Datatable添加数据,提示该行已经属于另一个表的解决方法
- map任务中,merge过程的实现方法
- asp.net实现数据从DataTable导入到Excel文件并创建表的方法
- List 转换 DataTable DataSet的方法
- ASP.Net【如何合并DataTable,并且去重复方法】