Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法强制转换类型为';MS.Internal.NamedObject';输入';System.Data.DataRowView';_C#_Datatable - Fatal编程技术网

C# 无法强制转换类型为';MS.Internal.NamedObject';输入';System.Data.DataRowView';

C# 无法强制转换类型为';MS.Internal.NamedObject';输入';System.Data.DataRowView';,c#,datatable,C#,Datatable,我有这段代码从datagrid中检索数据,然后存储在另一个datatable中。但我得到的例外是: “无法将'MS.Internal.NamedObject'类型的对象强制转换为'System.Data.DataRowView'类型。“dt.Rows.Add(dr.ItemArray)”之后出现此异常。 如果有任何故障或需要任何附加信息,请务必告诉我 代码: 感谢AVD,我的回答如下: foreach (DataRow d in _ds.Tables[0].Rows) {

我有这段代码从datagrid中检索数据,然后存储在另一个datatable中。但我得到的例外是:
“无法将'MS.Internal.NamedObject'类型的对象强制转换为'System.Data.DataRowView'类型。
“dt.Rows.Add(dr.ItemArray)”之后出现此异常。

如果有任何故障或需要任何附加信息,请务必告诉我

代码:


感谢AVD,我的回答如下:

foreach (DataRow d in _ds.Tables[0].Rows)
         {
             if (d["DataGridComboxBox_Control"].ToString() == "AVS_DB")
             {
                 qcId = d["DataGridTextBox_QCList1"].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());
                 logMessage = "Deploying files" + zipFolderPath;
                 Common.LogMessage(logMessage);
                 DeployFiles();
             }
         }

DataGrid.Items
可以包含一个
NewItemPlaceholder
,用于允许用户添加新项目。因此,您不能不加选择地迭代集合,或者过滤掉该项,或者迭代
ItemsSource

您需要定义DataTable
schema
。尝试只添加新数据行,而不是其项:dt.Rows.add(dr);最初我尝试了dt.Rows.Add(dr),但没有成功。然后尝试了dt.ImportRow(dr)和dt.Rows.Add(dr.ItemArray):仍然无法找出异常的原因hi AVD已定义DataTable的结构尝试使用dt.NewRow()创建新行然后手动填充它的列?对于
ItemsControl.Items
绑定到
ObservableCollection
(我也尝试了
List
,没有效果)。为什么
ItemsControl.Items
中应该有
newitemsplaceholder
?@dotNET:这是相同的属性,可能该功能已经在
ItemsControl
中实现了,因为它相当通用。
foreach (DataRow d in _ds.Tables[0].Rows)
         {
             if (d["DataGridComboxBox_Control"].ToString() == "AVS_DB")
             {
                 qcId = d["DataGridTextBox_QCList1"].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());
                 logMessage = "Deploying files" + zipFolderPath;
                 Common.LogMessage(logMessage);
                 DeployFiles();
             }
         }