在DataTable问题中添加一行

Jos*_*osh 1 c#

问候每个人 -

在下面的代码中,如果电子邮件地址不匹配,我正在尝试将现有DataTable(dtResult)中的一行添加到新的DataTable(dtCopyResult)中.所以我想我对ADO.NET的了解不尽如人意,因为无论何时我尝试运行下面的代码,我都会得到一个"This Row已经属于另一个表".请让我知道如何解决这个问题..

非常感谢

 if (checkBox1.Checked)  
                    {

                        for (int i = dtResult.Rows.Count - 1; i >= 0; i--)  //dtResult is a DataTable
                        {
                            foreach (object email in emails)  //emails is an ArrayList of email addresses
                            {
                                if (email.ToString().ToUpper() != dtResult.Rows[i][3].ToString().ToUpper())
                                {
                                    dtCopyResult.Rows.Add(dtResult.Rows[i]);  //dtCopyResult is a new blank DataTable that I'm trying to add rows to
                                }
                            }

                        }

                    }
Run Code Online (Sandbox Code Playgroud)

Hei*_*nzi 6

正如错误消息告诉您的那样,DataRow属于特定的DataTable; 你不能把它拿走并添加到另一个.你能做的也是