在日华人IT论坛

 找回密码
 立即注册

扫一扫,访问微社区

查看: 1029|回复: 0

简便的复制datatable的datarow的方法

[复制链接]
发表于 2012-5-16 16:06:15 | 显示全部楼层 |阅读模式
A Quick Way to Copy DataRow

Instead of copying DataRow column by column, the following code copies data in one line from the source to the destination row:
DataTable dtDest = new DataTable();
dtDest = dsActivity.Tables[0].Clone();
foreach(DataRow dr in dsSrc.Tables[0].Rows){
    DataRow newRow = dtDest .NewRow();
    newRow.ItemArray = dr.ItemArray;
    dtDest.Rows.Add(newRow);
}

Note:
The ImportRow method does the same thing, except that the RowState of source is preserved in the destination, whereas NewRow sets RowState to Added
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|在日华人IT论坛

GMT+8, 2024-11-21 21:23 , Processed in 0.039754 second(s), 15 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表