I am reading in an XML file into a Dataset, then adding a new column, then assigning a value to each row in that column.
My program creates the new column and I can see that it has the BitmapImage datatype by looking at it in the debug screen while its running and using a messagebox to toString its datatype.
But when i try to assign something to that row’s column, it remains as ‘{}’ and when I attempt to use it it gives the the error ‘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]);
}
When I run the assignment row, no error comes up, but nothing happens to the item array after the line is run.
I haven’t used
DataTablemuch, but I’d expectItemArrayto make a copy of the data, rather than returning a “live” array which theDataRowtracks. I wouldn’t really have expected that to work. Try just setting the value via the indexer:ItemArrayis really meant to get or set values in bulk, rather than for a single value.