Casting from a typed ICE Table to a standard DataTable

Yeah yeah it’s a necropost…

@darista to answer your question, here is how you can do it with an anonymous function at the top of your BPM if you are still looking.


Func<List<Ice.Bpm.TempTables.UD02TempRow>,DataTable> ToDataTable = (data) =>
        {
            PropertyDescriptorCollection properties =
                TypeDescriptor.GetProperties(typeof(UD02TempRow));
            DataTable table = new DataTable();
            foreach (PropertyDescriptor prop in properties)
            {
                Type myType =
                Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType;
             //   if(myType != null && !myType.FullName.Contains("Nullable<>")) 
             table.Columns.Add(prop.Name, myType);
            }
            foreach (UD02TempRow item in data)
            {
                DataRow row = table.NewRow();
                foreach (PropertyDescriptor prop in properties)
                {
                    row[prop.Name] = prop.GetValue(item) ?? DBNull.Value;
                }
                table.Rows.Add(row);
            }
            return table;
        };

USAGE:

var t = ToDataTable(ttUD02);

You’ll need at least these refs:
using System.Reflection;
using System.ComponentModel;

2 Likes