I'm trying to use DataTable.Import Row to copy the contents of one Datatable to another. I needed to do this because I changed the datatype of some fields in the destination table from String to Decimal. This is failing though on the Import row and giving the error:
"Input string was not in a correct format.Couldn't store <> in #X#_G-101_DISPLAY_VALUE_ONLY_1 Column. Expected type is Decimal."
What would you do about this?
Thanks
"Input string was not in a correct format.Couldn't store <> in #X#_G-101_DISPLAY_VALUE_ONLY_1 Column. Expected type is Decimal."
What would you do about this?
Thanks
Code:
[size=2][color=#2b91af][size=2][color=#2b91af]
DataTable[/color][/size][/color][/size][size=2] detailsTableClone = [/size][size=2][color=#0000ff][size=2][color=#0000ff]null[/color][/size][/color][/size][size=2];
[/size][size=2][color=#0000ff][size=2][color=#0000ff]foreach[/color][/size][/color][/size][size=2] ([/size][size=2][color=#2b91af][size=2][color=#2b91af]DataRow[/color][/size][/color][/size][size=2] dataRow [/size][size=2][color=#0000ff][size=2][color=#0000ff]in[/color][/size][/color][/size][size=2] detailsTable.Rows)
{
[/size][size=2][color=#0000ff][size=2][color=#0000ff]foreach[/color][/size][/color][/size][size=2] ([/size][size=2][color=#2b91af][size=2][color=#2b91af]DataColumn[/color][/size][/color][/size][size=2] dataColumn [/size][size=2][color=#0000ff][size=2][color=#0000ff]in[/color][/size][/color][/size][size=2] detailsTable.Columns)
{
[/size][size=2][color=#008000][size=2][color=#008000]// Clone detailsTable
[/color][/size][/color][/size][size=2]detailsTableClone = detailsTable.Clone();
[/size][size=2][color=#008000][size=2][color=#008000]// Create columns in the cloned table, and change datatype of columns containing DISPLAY_VALUE_ONLY
[/color][/size][/color][/size][size=2][/size][size=2][color=#008000][size=2][color=#008000]// to decimal datatype.
[/color][/size][/color][/size][size=2][/size][size=2][color=#0000ff][size=2][color=#0000ff]for[/color][/size][/color][/size][size=2] ([/size][size=2][color=#0000ff][size=2][color=#0000ff]int[/color][/size][/color][/size][size=2] i=0; i<detailsTableClone.Columns.Count; i++)
{
[/size][size=2][color=#2b91af][size=2][color=#2b91af]Debug[/color][/size][/color][/size][size=2].Print(detailsTableClone.Columns[i].ColumnName);
[/size][size=2][color=#0000ff][size=2][color=#0000ff]if[/color][/size][/color][/size][size=2] (detailsTableClone.Columns[i].ColumnName.Contains([/size][size=2][color=#a31515][size=2][color=#a31515]"DISPLAY_VALUE_ONLY"[/color][/size][/color][/size][size=2]))
{
detailsTableClone.Columns[i].DataType = System.[/size][size=2][color=#2b91af][size=2][color=#2b91af]Type[/color][/size][/color][/size][size=2].GetType([/size][size=2][color=#a31515][size=2][color=#a31515]"System.Decimal"[/color][/size][/color][/size][size=2]);
}
}
[/size][size=2][color=#008000][size=2][color=#008000]// Copy data into cloned table
[/color][/size][/color][/size][size=2][/size][size=2][color=#0000ff][size=2][color=#0000ff]foreach[/color][/size][/color][/size][size=2] ([/size][size=2][color=#2b91af][size=2][color=#2b91af]DataRow[/color][/size][/color][/size][size=2] dr [/size][size=2][color=#0000ff][size=2][color=#0000ff]in[/color][/size][/color][/size][size=2] detailsTable.Rows)
{
detailsTableClone.ImportRow(dr);
}
}
}
[/size]