中的DataTable如何修改數據類型?
DataTable dt = AuctionOrders.PayCarPrice(uid, payStatus, pageIndex, pageSize);
if (dt.Rows.Count > 0)
{
//新表
DataTable newDt = new DataTable();
List<string> listColums = new List<string>();
//復制表結夠
newDt = dt.Clone();
//新表中的列數據類型為Decmail的改為string
foreach (DataColumn col in newDt.Columns)
{
listColums.Add(col.ColumnName);
if (col.DataType.FullName == "System.Decimal")
{
col.DataType = Type.GetType("System.String");
}
}
foreach (DataRow row in dt.Rows)
{
DataRow newDtRow = newDt.NewRow();
foreach(DataColumn column in dt.Columns)
{
if (column.DataType.FullName == "System.Decimal")
{
newDtRow[column.ColumnName] = (Convert.ToDecimal(row[column.ColumnName]) / 10000).ToString("c") + "萬";
}
else
{
newDtRow[column.ColumnName] = row[column.ColumnName];
}
}
newDt.Rows.Add(newDtRow);
}
var obj = new { state = true, message = newDt };
Response.Write(JsonConvert.SerializeObject(obj));
}
else
{
var obj = new { state = false, message = "沒有查詢到信息" };
Response.Write(JsonConvert.SerializeObject(obj));