日期:2014-05-18 浏览次数:20900 次
DataTable myNewTable = new DataTable(); foreach (DataRow myDR in myDTC[0].Rows) { DataRow myNewDR=myNewTable.NewRow(); foreach (DataColumn myDC in myDTC[0].Columns) { String myValue = myDC.ColumnName.ToString().Trim(); String minValue,maxValue; // //对数量进行判断,并拆分为最大值和最小值(自定义类实现,这里没有问题) // if (myDR[myDC] != DBNull.Value && myDR[myDC].ToString() != "") { String test = myDR[myDC].ToString().Trim(); SpecialCharExist mySCE = new SpecialCharExist(); List<String> myCompositionList = new List<string>(); bool flagRC = mySCE.whetherRelationCharExist(test, out myCompositionList); if (flagRC == true) { string[] myCompositionResult = myCompositionList.ToArray(); minValue = myCompositionResult[0]; maxValue = myCompositionResult[1]; } else { minValue = test; maxValue = test; } } else { minValue = "0"; maxValue = "0"; } // //对新表增加列并进行赋值,赋给其最小值与最大值,问题可能出现在这里,但是我找不到啦! // DataColumn myNewDC1 = myNewTable.Columns.Add(myValue + "minValue".ToString(), typeof(double)); myNewDR[myValue + "minValue"] = Convert.ToDouble(minValue); DataColumn myNewDC2 = myNewTable.Columns.Add(myValue + "maxValue".ToString(), typeof(double)); myNewDR[myValue + "maxValue"] = Convert.ToDouble(maxValue); /* myNewTable.Columns.Add(myValue+"minValue",typeof(double)); myNewTable.Columns.Add(myValue+"maxValue",typeof(double)); myNewDR[myElement + "minValue"] = Convert.ToDouble(minValue); myNewDR[myElement + "maxValue"] = Convert.ToDouble(maxValue); */ } myNewTable.Rows.Add(myNewDR); MessageBox.Show(myNewTable.Rows[0][0].ToString()); }