I saw another post in this forum demonstrating how to create a datatable from either Ilist or IQuery but I cant seem to get it to work and I am wondering if the code is wrong. I am desperate to get this working. Heres the code
Code:
public class TypedListGenerator {
public TypedListGenerator(IList nestedArrays) {
this._nestedArrays = nestedArrays;
this._view = new DataTable();
}
IList _nestedArrays;
DataTable _view;
public void AddColumn(string name) {
this.AddColumn(name, typeof(String));
}
public void AddColumn(string name, Type type) {
this._view.Columns.Add(name, type);
}
public ITypedList Format() {
if(this._view.Rows.Count != this._nestedArrays.Count) {
foreach(object[] row in this._nestedArrays) {
this._view.Rows.Add(row);
}
}
return this._view.DefaultView;
}
}
The code breaks on the line:
foreach(object[] row in this._nestedArrays)
with the error :
specified cast is not valid.
I cant see why, I realise this might be more of a .net problem but I'm not sure.
Thanks