問候everyone-添加行到DataTable問題
在我的代碼下面我試圖從現有的數據表(dtResult)添加一行到一個新的DataTable(dtCopyResult)如果電子郵件地址不匹配。所以我猜我對ADO.NET的瞭解不夠全面,因爲每當我嘗試運行我的下面的代碼時,我都會得到一個「This Row already already belong to another table」。請讓我知道我該如何解決這個..
非常感謝
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
}
}
}
}
嘗試使用CopyResult.Rows.Add(new dtResult.Rows [i]);只是猜測 – Gage 2010-11-16 16:54:18