原始代码
DataTable dtTarget = new DataTable();
if (dt != null && dt.Rows.Count>0)
{
dtTarget.Columns.Add(new DataColumn("businessNo"));
dtTarget.Columns.Add(new DataColumn("yhdOrderNo"));
dtTarget.Columns.Add(new DataColumn("trdOrderNo"));
dtTarget.Columns.Add(new DataColumn("transType"));
dtTarget.Columns.Add(new DataColumn("incomeAmt"));
dtTarget.Columns.Add(new DataColumn("expendAmt"));
dtTarget.Columns.Add(new DataColumn("transTime"));
dtTarget.Columns.Add(new DataColumn("remark"));
foreach (DataRow item1 in dt.Rows)
{
dtTarget.Rows.Add(
item1["交易流水号"], ToString(),
item1["1号店订单号"],ToString(),
item1["商城订单号"].ToString(),
(item1["订单类型"].ToString() =="1" ?"正向订单":"退货订单"),
Convert.ToDouble(item1["正向金额"].ToString() == "" ? 0 : item1["正向金额"]).ToString("0.00"),
Convert.ToDouble(item1["退货金额"].ToString() == "" ? 0 : item1["退货金额"]).ToString("0.00"),
item1["订单完成时间"].ToString(),
item1["备注"].ToString()
);
}
}
错误消息为:
输入数组长度大于此表中的列数。
FUCK,
绑定值的时候,ToString() 前面写成了逗号!