I have a data stored in Json. I can dynamically create the datatable columns but when i load the data, its not loaded.
dt = new DataTable();
Type firstType =new TickerData().GetType();
foreach (PropertyInfo propertyInfo in firstType.GetProperties())
{
dt.Columns.Add(propertyInfo.Name, propertyInfo.PropertyType);
}
foreach (string file in filePaths)
{
TickerData td=getSymbolJson(file);
DataRow newrow =dt.NewRow();
foreach (PropertyInfo propertyInfo in td.GetType().GetProperties())
{
newrow[propertyInfo.Name] = propertyInfo.GetValue(td, null);
}
dt.ImportRow(newrow);
}
I am missing something. Can you spot it? The data is there in the json. i can track it in visual studio
newrow has the data as you can see from the watch window
But the dataset visualizer shows no data for the datatable.
use dt.Rows.Add(newrow); instead of dt.ImportRow(newrow);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.