登录
首页 » C#源码 » C# 复制和删除数据表指定行数据

C# 复制和删除数据表指定行数据

于 2022-04-17 发布 文件大小:29.29 kB
0 47
下载积分: 2 下载次数: 1

代码说明:

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

下载说明:请别用迅雷下载,失败请重下,重下不扣分!

发表评论

0 个回复

  • C# 在LINQ to DataSet中对分组操作执行子查询
    C# 在LINQ to DataSet中对分组操作执行子查询,相关代码:   private void button1_Click(object sender, EventArgs e)   {//在LINQ to DataSet中对分组操作执行子查询    SqlConnection MyConnection = new SqlConnection();    MyConnection.ConnectionString = @"Data Source =.SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=True";    MyConnection.Open();    SqlCommand MyCommand = new SqlCommand("Select * From Orders ", MyConnection);    DataSet MySet = new DataSet();    SqlDataAdapter MyAdapter = new SqlDataAdapter(MyCommand);    MyAdapter.Fill(MySet);    DataTable MyQueryTable = MySet.Tables[0];    var MyQuery = from MyOrder in MyQueryTable.AsEnumerable()    orderby MyOrder.Field("ShipCity")    group MyOrder by MyOrder.Field("ShipCity") into g    select new    {    MyCity = g.Key,    MyMaxFreight = (from MyData in g select MyData.Field("Freight")).Max()   
    2022-01-27 20:20:32下载
    积分:1
  • C# timer应用范例:左右飘动的窗体
    C# 创建一个飘动的窗体,左右飘动,主要是对Timer的控制,基本的原理是:窗体的左上角横坐标随着timer1不断加一,窗体的左上角横坐标随着timer2不断减一,这个过程由Timer控制,因此你要写出一个循环,来控制Timer不停变化,比如timer不断加一:   Point p = new Point(this.DesktopLocation.X + 1, this.DesktopLocation.Y);   this.DesktopLocation = p;   if (p.X == 630)   {    timer1.Enabled = false;    timer2.Enabled = true;   }   以上代码的执行我们放入到private void timer1_Tick私有函数中,运行程序后即运行该函数。
    2023-03-26 23:00:04下载
    积分:1
  • C#制作闪烁的按钮特效
    C#制作闪烁的按钮特效,打开本程序,运行后窗口上的按钮快速闪烁,可起到吸引人注意的效果,实现方法基于WPF的编程概念。运行效果如演示截图所示。注意:不是窗口闪烁,是窗口内的按钮闪烁哦。
    2022-10-31 16:30:02下载
    积分:1
  • C# 使用 tabControl创建窗体TAB效果
    C# 使用 tabControl创建窗体TAB选项卡效果,大家都熟悉的功能,这个例子比较基础,面向C#的初学者,下面是实现本功能的核心代码:   private void Form1_Load(object sender, EventArgs e)   {    tabControl1.ImageList = imageList1;    tabPage1.ImageIndex = 0;    tabPage1.Text = "选项卡1";    tabPage2.ImageIndex = 0;    tabPage2.Text = "选项卡2";   }   本TAB运行效果请参见截图,完整源码请下载。
    2022-08-22 06:09:52下载
    积分:1
  • C# 显示DataGridView控件中选定的单元格、行和列
    Visual C#显示选择的DataGridView单元格,获取DataGridView控件中选定的单元格、行和列,测试前请连接好数据库,实现此功能核心代码如下:   if (customersDataGridView.AreAllCellsSelected(true))   {    MessageBox.Show("所有单元格已经被选择!", "信息提示",MessageBoxButtons.OK);   }   else   {    System.Text.StringBuilder MyInfo =new System.Text.StringBuilder();    for (int i = 0;    i < MyCount; i++)    {    MyInfo.Append("行号: ");    MyInfo.Append(customersDataGridView.SelectedCells[i].RowIndex.ToString());    MyInfo.Append(", 列号: ");    MyInfo.Append(customersDataGridView.SelectedCells[i].ColumnIndex.ToString());    MyInfo.Append(", 单元格值: ");    MyInfo.Append(customersDataGridView.SelectedCells[i].Value.ToString());    MyInfo.Append(Environment.NewLine);    }    MyInfo.Append("一共选择了: " + MyCount.ToString()+"个单元格");    MessageBox.Show(MyInfo.ToString(), "信息提示", MessageBoxButtons.OK);   }
    2022-03-18 13:11:05下载
    积分:1
  • C# 精仿漂亮360安全卫士窗口
    C# 精仿漂亮360安全卫士窗口 自定义360风格的窗体,使用GDI方式渲染,拥有ToolTip属性的Form基类,可设置是否允许窗体改变大小,包括了系统按钮控制器,对其用参数所构建的窗体系统按钮的控制,造成的阴影效果相当的平滑,且窗口元素可随窗口的大小改变而改变,源码里面的窗体自绘辅助类、自定义窗口类我觉得是相当实用的。
    2022-08-04 09:09:44下载
    积分:1
  • PX4飞控机身主板
    配套硬件配置: CPU:STM32F205 主频:168 MHz RAM:256 KB FLASH:2 MB闪存 传感器:3D ACC /陀螺仪/ MAG/气压 其它: microSD插槽,5个UART,CAN,I2C,SPI,ADC,等
    2022-01-28 08:21:53下载
    积分:1
  • C# 使用Socket连接远程主机的例子
    C# UseSocket例子,使用Socket连接远程主机,其核心是使用Socket的构造函数实例化一个Socket对象,用来连接远程主机,再具体就是调用Connect方法连接远程主机,在成功连接主机后,调用自定义方法ConnectSocket,使用指定的服务器名和端口号实例化一个Socket对象,将请求发送到连接的服务器,从绑定的Socket接收数据,将接收到的数据转换为字符串类型,调用自定义方法SocketSendReceive获取指定主机的主页面内容。   远程连接部分的实现如下:   //使用指定的IP地址和端口号实例化IPEndPoint对象   IPEndPoint IPEPoint = new IPEndPoint(address, port);   //使用Socket的构造函数实例化一个Socket对象,以便用来连接远程主机   Socket newSocket = new Socket(IPEPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);   newSocket.Connect(IPEPoint); //调用Connect方法连接远程主机   在创建远程连接之前,要循环遍历得到的IP地址列表。
    2022-04-29 10:57:31下载
    积分:1
  • 7Zip
    This file is part of SevenZipSharp.    SevenZipSharp is free software: you can redistribute it and/or modify    it under the terms of the GNU Lesser General Public License as published by    the Free Software Foundation, either version 3 of the License, or    (at your option) any later version.    SevenZipSharp is distributed in the hope that it will be useful,    but WITHOUT ANY WARRANTY; without even the implied warranty of    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    GNU Lesser General Public License for more details.    You should have received a copy of the GNU Lesser General Public License    along with SevenZipSharp.  If not, see .
    2022-07-20 00:09:31下载
    积分:1
  • 104规约IEC60870-5-104
    完整的能通过vs2010运行的IEC-104主站和辅站源代码,本人在公司实习亲自编写的。对初学者帮助很大而且对104协议的剖析很清楚。
    2023-05-22 09:00:20下载
    积分:1
  • 696524资源总数
  • 103986会员总数
  • 80今日下载