我有一種情況,我需要修改現有的DataTable
。 @Shai Cohen提供了代碼,但由於實時數據不同,我在我正在修改的列上發生了異常MaxLimit違例。以編程方式創建的DataTable列MaxLength錯誤
我試着改變與代碼中的代碼,但它一直在拋出錯誤。下面是代碼(見內我的意見):
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;
}
爲什麼這裏涉及的像素? – 2013-03-11 17:17:36
什麼是例外? – 2013-03-11 17:23:37
爲什麼downvote ???? @AlexFilipovici我已經說過在頂級MaxLimit違規...像素,因爲我不知道還有什麼 - 這就是爲什麼張貼在這裏,因爲我不是專家。 – Risho 2013-03-11 19:33:37