0
我正在将XML文件读入数据集,然后添加一个新列,然后为该列中的每一行分配一个值。未分配数据表项目数组
我的程序创建新列,我可以看到它具有BitmapImage数据类型,通过在调试屏幕中查看它,同时它的运行和使用messagebox来toString其数据类型。
但是,当我尝试将某些东西分配给该行的列时,它仍然是'{}',当我尝试使用它时,它会给出错误'Unable to cast type DBNull to BitmapImage';
ItemDS = new DataSet();
ItemDS.ReadXml(homeFolder + @"Items.xml", XmlReadMode.InferSchema);
ItemDS.Tables[0].Columns.Add("pic", typeof(BitmapImage));
MessageBox.Show(ItemDS.Tables[0].Columns[5].DataType.ToString());
foreach (DataRow theRow in ItemDS.Tables[0].Rows)
{
try
{
theRow.ItemArray[5] = (SquareImageFromFile(NewDeployFolder + @"assets\images\items\" + theRow.ItemArray[3].ToString(), 120));
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
combItem.Items.Add(theRow.ItemArray[0]);
}
当我运行赋值行时,没有错误出现,但在运行该行之后没有发生任何事情。
呃,我就是这样一个小丑,谢谢你修复我的语法,现在这个作品完美无缺! – user1178412 2012-02-11 09:38:27