group_number synch_Experimentguid course_name
0 4 语文1
0 3 计算机
0 1 物理
1 3 计算机
1 4 语文1
2 3 计算机
2 1 物理
3 3 计算机
4 1 物理
5 4 语文1需要如下结果
group_number synch_Experimentguid course_name
0 4,3,1 语文1 ,计算机,物理
1 3,4 计算机,语文1
2 3,1 计算机,物理
3 3 计算机
4 1 物理
5 4 语文1
谢谢大家帮助上面的是dt1
生成dt2
group_number 是int
synch_Experimentguid 和 course_name 是string
0 4 语文1
0 3 计算机
0 1 物理
1 3 计算机
1 4 语文1
2 3 计算机
2 1 物理
3 3 计算机
4 1 物理
5 4 语文1需要如下结果
group_number synch_Experimentguid course_name
0 4,3,1 语文1 ,计算机,物理
1 3,4 计算机,语文1
2 3,1 计算机,物理
3 3 计算机
4 1 物理
5 4 语文1
谢谢大家帮助上面的是dt1
生成dt2
group_number 是int
synch_Experimentguid 和 course_name 是string
不用Sql
int count = dt.Rows.Count;
DataTable result = dt.Clone();
for(int i = 0 ; i < count;i++)
{
DataRow row = dt.Rows[i];
if (!ht.Contains(row["group_number"].ToString()))
{
DataRow temp = result.NewRow();
temp["group_number"] = row["group_number"];
temp["synch_Experimentguid"] = "";
temp["course_name"] = "";
result.Rows.Add(temp);
ht.Add(row["group_number"].ToString(),temp);
}
DataRow r = (DataRow)ht[row["group_number"].ToString()];
if (r["synch_Experimentguid"].ToString().Length > 0)
{
r["synch_Experimentguid"] = r["synch_Experimentguid"].ToString() + "," + row["synch_Experimentguid"];
}
else
{
r["synch_Experimentguid"] = row["synch_Experimentguid"];
}
//course_name跟synch_Experimentguid一样
}
谢谢