DataTable TT=new DataTable ();
DataRow ce = TT.NewRow();
IList<CallEntity> list = new IList<CallEntity>;foreach (CallEntity call in list)
{
ce["Id"] = 1;
ce["StoreCode"] = call.StoreCode;///店铺号
ce["StoreName"] = call.StoreName != null ? call.StoreName : "测试店铺";///店铺名
ce["Num"] = 1;///店铺数量 DataRow[] rows = TT.Select("StoreCode='" + call.StoreCode + "'");
if (rows.Length > 0)
{
rows[0]["Num"] = Convert.ToInt32(ce["Num"]) + Convert.ToInt32(rows[0]["Num"]);
}
else
{
TT.Rows.Add(ce.ItemArray);
}
}
return TT;
=============================
上面那个Id是自增列,由于list里面有重复数据,不知道Id怎么写,Id不是在数据库里获取的
DataRow ce = TT.NewRow();
IList<CallEntity> list = new IList<CallEntity>;foreach (CallEntity call in list)
{
ce["Id"] = 1;
ce["StoreCode"] = call.StoreCode;///店铺号
ce["StoreName"] = call.StoreName != null ? call.StoreName : "测试店铺";///店铺名
ce["Num"] = 1;///店铺数量 DataRow[] rows = TT.Select("StoreCode='" + call.StoreCode + "'");
if (rows.Length > 0)
{
rows[0]["Num"] = Convert.ToInt32(ce["Num"]) + Convert.ToInt32(rows[0]["Num"]);
}
else
{
TT.Rows.Add(ce.ItemArray);
}
}
return TT;
=============================
上面那个Id是自增列,由于list里面有重复数据,不知道Id怎么写,Id不是在数据库里获取的
foreach (CallEntity call in list)
{
ce["Id"] = 1;
把这个改成
int rowindex=1;
foreach (CallEntity call in list)
{
ce["Id"] =rowindex.tostring();
rowindex=rowindex+1;看看,不知道是不是想要的结果
这个是初始的,还没写