我有这段代码可以从数据网格中检索数据,然后将其存储在另一个数据表中。但我得到的例外是:
"Unable to cast object of type 'MS.Internal.NamedObject' to type 'System.Data.DataRowView'.
“这个例外是在"dt.Rows.Add(dr.ItemArray)"
如果有任何故障或需要任何其他信息,请告诉我。
代码:
DataTable dt = new DataTable();
DataColumn c1 = new DataColumn("IsActive", typeof(bool));
dt.Columns.Add(c1);
DataColumn c2 = new DataColumn("DataGridTextBox_QCList1", typeof(string));
c2.MaxLength = 500;
dt.Columns.Add(c2);
DataColumn c3 = new DataColumn("DataGridTextBox_QCSummary", typeof(string));
c3.MaxLength = 500;
dt.Columns.Add(c3);
DataColumn c4 = new DataColumn("DataGridComboxBox_Control", typeof(string));
c4.MaxLength = 500;
dt.Columns.Add(c4);
foreach (DataRowView d in dtgQCNumbers.Items)
{
DataRow dr = d.Row;
dt.Rows.Add(dr.ItemArray);
dt.AcceptChanges();
}
foreach (DataRow row in dt.Rows)
{
qcId = row["QC_ID"].ToString();
zipFolderPath = baseFolderPath;
patternFiles = Directory.GetFiles(zipFolderPath, "*.zip");
logMessage = "Unzipping file from path" + zipFolderPath + " \n file name:" + patternFiles[0];
Common.LogMessage(logMessage);
UnZipReleasePatch(zipFolderPath, patternFiles.First());
//deploy release patch.
logMessage = "Deploying files" + zipFolderPath;
Common.LogMessage(logMessage);
DeployFiles();
}