资 源 简 介
C# 复制和删除数据表指定行数据,主要是完成了两项功能,删除目标数据表的选择行的整行数据,将源数据表的选择行数据复制到目标数据表,这两个功能的实现思路和代码演示如下:
private void Form1_Load(object sender, EventArgs e)
{
MySourceTable = new DataTable();
var MyConnectString=@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:Northwind.mdb";
var MySQL = "Select * From 客户";
var MyAdapter=new OleDbDataAdapter(MySQL,MyConnectString);
MyAdapter.Fill(MySourceTable);
this.DataGridView1.DataSource = MySourceTable;
MyTargetTable = MySourceTable.Clone();
this.DataGridView2.DataSource = MyTargetTable;
}
private void Button1_Click(object sender, EventArgs e)
{//将源数据表的选择行数据复制到目标数据表
var MyID= "客户ID=;
MyID = MyID + this.DataGridView1.CurrentRow.Cells[0].Value.ToString() +";
MyTargetTable.ImportRow(this.MySourceTable.Select(MyID)[0]);
}
private void Button2_Click(object sender, EventArgs e)
{//删除目标数据表的选择行的整行数据
var MyID = "客户ID=;
MyID = MyID +this.DataGridView2.CurrentRow.Cells[0].Value.ToString