You're right Stefan, I missed that crucial part of the code. This is what I use for v8, it does a lookup for the columns and matches them and sets the values assuming the column names are the same from the source datasource to the target or Kentico custom table.
/// <summary>
/// Creates an item for a custom table and dynamically adds the columns data based on the classinfo and row column comparison
/// </summary>
/// <param name="Dci"></param>
/// <param name="Row"></param>
/// <returns></returns>
public static bool CreateCustomTableItem(DataClassInfo Dci, DataRow Row)
{
bool okInsert = false;
if (Dci == null)
{
throw new Exception("Data class info cannot be null.");
}
else
{
// Creates new Custom table item provider
CustomTableItemProvider customTableProvider = new CustomTableItemProvider(Dci.ClassName);
// Creates new custom table item object
CustomTableItem newCustomTableItem = CustomTableItem.New(Dci.ClassName, Row);
List<string> classProperties = new List<string>();
// get the class definition
var doc = XDocument.Parse(Dci.ClassFormDefinition);
// get a list of all the tables properties by column value
List<string> elements = doc.Descendants("field").Select(el => el.Attribute("column").Value).ToList();
// got the class properties now compare
foreach (string s in elements)
{
// see if the class info contains the column in the data row passed in this method
if (Row.Table.Columns.Contains(s))
{
// contains the column so set a value
newCustomTableItem.SetValue(s, Row[s]);
okInsert = true;
}
}
if (okInsert)
{
// Inserts the custom table item into database
newCustomTableItem.Insert();
}
}
return okInsert;
}