とのタプルのリスト私はこのようなタプルのリストを持っている:グループ、ソートのLINQ
List<Tuple<int,int, string>> list;
充填された値を使用した:
1,200,"somelabelForHeaderA"
2,200,"sometextA"
3,200,"sometextA"
4,222,"somelabelForHeaderB"
5,222,"sometextB"
6,222,"sometextB"
7,300,"somelabelForHeaderC"
8,300,"sometextC"
9,401,"somelabelForHeaderD"
10,401,"sometextD"
11,401,"sometextD"
12,401,"sometextD"
は今、私は何をしたいのか、このようなソートとグループです:
1,200,"somelabelForHeaderA" <== ***Must Be Inserted in Column 1 Row 1***
2,200,"sometextA sometextA" <== ***Must Be Inserted in Column 2 Row 1***
3,222,"somelabelForHeaderB" <== ***Must Be Inserted in Column 1 Row 2***
4,222,"sometextB sometextB" <== ***Must Be Inserted in Column 2 Row 2***
5,300,"somelabelForHeaderC" <== ***Must Be Inserted in Column 1 Row 3***
6,300,"sometextC" <== ***Must Be Inserted in Column 2 Row 3***
7,401,"somelabelForHeaderD" <== ***Must Be Inserted in Column 1 Row 4***
8,401,"sometextD sometextD sometextD" <== ***Insert in Column 2 Row 4***
を入力し、それぞれの「somelabelForHeader」と「sometext」を1つの行に挿入します。
これは私の知る限り行くようです:グループと連結私ができる上記のコードですべてのテキスト
var grouped = list.GroupBy(t => t.Item2, t => t.Item3)
.Select(g => Tuple.Create(g.Key, string.Join("\n", g)));
foreach (var groups in grouped)
{
using (SqlConnection sqlconnection = new SqlConnection(Connection_String))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.Connection = sqlconnection;
cmd.CommandType = CommandType.Text;
cmd.CommandText = query;
cmd.Parameters.AddWithValue("@a", groups.Item2);
cmd.Parameters.AddWithValue("@c", "???");
try
{
sqlconnection.Open();
cmd.ExecuteNonQuery();
}
catch (SqlException ex)
{
}
}
}
が、どのように挿入する前に、最初の行をソートし、抽出することができますか?