C # puts a DataTable row into another DataTable

Source: Internet
Author: User

http://blog.csdn.net/huyu107/article/details/53509171

Overview

Take a row from one DataTable and put it in another DataTable. Error: the row already belongs to another table .

The first method:
DataTable dt = new DataTable();dt = ds.Tables["All"].Clone();//克隆All的结构传递给dtDataRow[] dr=this.dataSet31.Tables["Product"].Select("bc=1"); //通过条件得到符合条件的行for(int i=0;i<dr.Length;i++){ //将数组元素加入表... dt.Rows.Add(dr[i]);//出错提示为:该行已经属于另一个表}// 修改后DataTable dt = new DataTable();dt = ds.Tables["All"].Clone();//克隆All的结构传递给dtDataRow[] dr=this.dataSet31.Tables["Product"].Select("bc=1"); //通过条件得到符合条件的行for(int i=0;i<dr.Length;i++){ //将数组元素加入表... dt.Rows.Add(dr[i].ItemArray);}
The second method:
DataTable DT1=New DataTable ();D atatable CALCDT=New DataTable ();//dt1 just get the table structure, no data; //calcdt has a table structure, with data //original method foreach (DataRow Dr in calcdt. Rows) {Dt1. Rows//Improved Method DataRow Drcalc;foreach (DataRow Dr in Calcdtrows) {Drcalc = dt1= dr. Rows               

C # places a DataTable row into another DataTable

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.