将几条记录从第一数据表复制到第二数据表 [英] copy few records from first datatable to second datatable

查看:80
本文介绍了将几条记录从第一数据表复制到第二数据表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个数据表(dt1和dt2)
dt1中的第1至5列
我想将几条记录从第一个数据表复制到第二个数据表(在dt2中复制第1,2,3列)

怎么样?

谢谢


如何将数据表指定列复制到另一个Datat功能?


在C#中,我使用一个数据表概念,在该数据表中有7列,
现在,我要复制第一个新数据表的前5个Coulmns,该怎么办?

源表名称-天数

日期|第1天|插槽1 |第2天|插槽2 |第3天|插槽3

上午9:00 |邀请| A,0 |邀请| B,0 |邀请| C,0
上午9:20 |邀请| A,1 |邀请| B,1 |邀请| C,1


新的Datable名称:dtInternational

日期|第1天|插槽1 |第2天|插槽2

上午9:00 |邀请| A,0 |邀请| B,0
上午9:20 |邀请| A,1 |邀请| B,1

i have a two datatable(dt1 and dt2)
column 1 to 5 in dt1
and i want to copy few records from first datatable to second datatable(copy column 1,2,3 in dt2)

how?

thanks


How I copy data table specifiy columns to another Datat able?


In C# , I m using one datatable concept, In that datatable had 7 columns,
Now I want to copy first 5 Coulmns for first New Datatable How do I this ?

Source Table Name - Days

Date | Day1 | Slot 1 | Day 2 | Slot 2 | Day 3 | Slot 3

9:00 AM | Invite | A,0 | Invite | B,0 | Invite | C,0
9:20 AM | Invite | A,1 | Invite | B,1 | Invite | C,1


New Datable Name : dtInternational

Date | Day1 | Slot 1 | Day 2 | Slot 2

9:00 AM | Invite | A,0 | Invite | B,0
9:20 AM | Invite | A,1 | Invite | B,1

推荐答案



使用以下查询

Hi,

Use the below query

INSERT INTO dt2 VALUES as
                 SELECT col1,col2,col3 FROM dt1



请确保后续列的数据类型和长度相同.

您还可以在表2中指定要在其上插入数据的列名.

如下



Please make sure that data type and length of subsequent columns are same.

You can also specify column name in table 2 on which column you want to insert data.

as below

INSERT INTO dt2<columns name in which you want to insert the data.> VALUES as
                 SELECT col1,col2,col3 FROM dt1


我的朋友,

对数据表应用选择查询,您将从一个数据表中选择行到另一个数据表.

http://www.dotnetperls.com/datatable-select [ http://msdn.microsoft.com/en-us/library/det4aw50.aspx [ ^ ]
i friend,

Apply a select query for the data table, you will get the selected rows from one datatable to another datatable.

http://www.dotnetperls.com/datatable-select[^]

http://msdn.microsoft.com/en-us/library/det4aw50.aspx[^]



通过下面的查询,您可以将列名称也写在where条件中.

DataRow []行= datatable.Select(''TOP 5'');
hi ,
With below query you can write the column names also ans where condition also.

DataRow[] rows = datatable.Select(''TOP 5'');


这篇关于将几条记录从第一数据表复制到第二数据表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆