惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

爱范儿
爱范儿
博客园_首页
W
WeLiveSecurity
S
Secure Thoughts
S
Security @ Cisco Blogs
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Hugging Face - Blog
Hugging Face - Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
H
Hacker News: Front Page
Project Zero
Project Zero
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
U
Unit 42
N
News and Events Feed by Topic
N
News and Events Feed by Topic
Hacker News - Newest:
Hacker News - Newest: "LLM"
Forbes - Security
Forbes - Security
T
Tor Project blog
I
Intezer
B
Blog
F
Full Disclosure
Security Archives - TechRepublic
Security Archives - TechRepublic
F
Fortinet All Blogs
Schneier on Security
Schneier on Security
T
Threat Research - Cisco Blogs
AI
AI
Google DeepMind News
Google DeepMind News
L
LINUX DO - 最新话题
Cloudbric
Cloudbric
L
Lohrmann on Cybersecurity
WordPress大学
WordPress大学
博客园 - 聂微东
雷峰网
雷峰网
P
Privacy International News Feed
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
PCI Perspectives
PCI Perspectives
Y
Y Combinator Blog
Spread Privacy
Spread Privacy
Simon Willison's Weblog
Simon Willison's Weblog
罗磊的独立博客
Vercel News
Vercel News
A
Arctic Wolf
The Register - Security
The Register - Security
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Microsoft Azure Blog
Microsoft Azure Blog
H
Heimdal Security Blog
Know Your Adversary
Know Your Adversary
P
Proofpoint News Feed
C
Cybersecurity and Infrastructure Security Agency CISA
P
Proofpoint News Feed

博客园 - Daniel Pang

pcanywhere失去连接的一个解决方法 JS格式化日期字符串 - Daniel Pang - 博客园 [软件共享]将数据库中的数据导出为SQL脚本 对文件下载的补充 - Daniel Pang - 博客园 IBatisNet + Castle 开发相关文章 [IBatisNet]关于返回DataTable的一点问题 深圳电话订票基本步骤及所有的取票点地址电话 Automatic Transaction Management Facility 使用 - Daniel Pang IBatisnet Facility 的几种配置 - Daniel Pang IBatisNet -- 保护你的配置文件及映射文件信息 Rational Rose 加载出错的问题 修改Sql server中列的属性脚本 字符串加密方法 ERP术语 英文对照(部分)(参考) 一个关于SQL2005的问题 动态加载TreeNode -- ComponentArt TreeView - Daniel Pang 使用IBatisNet + Castle 开发DotNet软件 JS--屏蔽浏览器右键菜单 Excel的导出操作 - Daniel Pang - 博客园
复制DataTable的一种方法
Daniel Pang · 2007-03-07 · via 博客园 - Daniel Pang

      如果将程序返回的DataTable加入到自己定义的一个DataSet中,直接用ds.Tables.Add(dt)的方法,就会出现“该DataTable已属于另外一个DataSet”的错误。这时候我们需要建一个新的DataTable,并将原来的DataTable的结构及数据导入到新的DataTable中,这时候就可以使用下面的方法(当然方法并不是唯一的):

/// <summary>
        
/// 复制DataTable
        
/// </summary>
        
/// <param name="copyDt">数据源</param>
        
/// <param name="tableName">新DataTable名称</param>
        
/// <returns>复制后的DataTable</returns>

        private DataTable CopyDataTable(DataTable copyDt, string tableName)
        
{
            DataTable dt 
= new DataTable(tableName);
            
foreach (DataColumn columm in copyDt.Columns)
            
{
                dt.Columns.Add(columm.ColumnName,columm.DataType);
            }


            
foreach (DataRow row in copyDt.Rows)
            
{
                dt.BeginInit();
                dt.ImportRow(row);
                dt.EndInit();
            }


            
return dt;
        }