我有一种情况需要修改现有的DataTable
. @Shai Cohen 提供了代码,但由于实时数据不同,我正在修改的列上出现异常 MaxLimit 违规。
我试图更改代码中的 with 但它不断抛出错误。这是代码(请参阅我的评论):
public DataTable PrepareDataTable(DataTable dtResults)
{
string[] subCategories = new string[3] {"Critical Down Time", "Critical Outage", "Total Repair Time"};
DataTable dtOutput = dtResults.Clone();
DataRow drOutput = null;
DataRow[] drResults = null;
var categories = dtResults.AsEnumerable().Select(r => r["Category"]).Distinct().ToList();
foreach (string category in categories)
{
for (int i = 0; i < subCategories.Length ; i++)
{
drOutput = dtOutput.NewRow();
drOutput["Category"] = category;
drOutput["SubCategory"] = subCategories[i];
drResults = dtResults.Select(String.Format("Category = '{0}' AND SubCategory = '{1}'", category, subCategories[i]));
if(drResults.Length > 0)
{
foreach(DataColumn column in dtResults.Columns)
{
drOutput[column.ColumnName] = drResults[0][column.ColumnName];
**I've tried** drOutput[column.MaxLength] = Unit.Pixel(500);
**or just a number but no use**
}
}
**Error >>>** dtOutput.Rows.Add(drOutput);
}
drOutput = dtOutput.NewRow();
dtOutput.Rows.Add(drOutput);
}
return dtOutput;
}