私は C# で "while" ループを実行しています。これは、DB からいくつかのレコードを取得しています。ループの最後のレコードを検出/検索する最良の方法は何ですか? これは可能ですか?
これが私のコードです:
while (sdr.Read())
{
//Pull each line from DB
the_title = sdr["the_title"].ToString();
the_cats = sdr["the_category"].ToString();
the_tags = sdr["the_tags"].ToString();
the_date = sdr["the_date"].ToString();
//Start file creation
writer.WriteLine("[");
writer.WriteLine("\"" + the_title + "\", ");
writer.WriteLine("\"" + the_cats + "\", ");
writer.WriteLine("\"" + the_tags + "\", ");
writer.WriteLine("\"" + the_date + "\", ");
writer.WriteLine("\"<a href=\\\"#\\\" class=\\\"sepV_a\\\" title=\\\"Edit\\\"><i class=\\\"icon-pencil\\\"></i></a>\"");
writer.WriteLine("],");
}
writer.WriteLine("]");
writer.WriteLine("}");
writer.Close();
私が抱えている問題は、コードの最後の行「writer.WriteLine("],");」にあります。DB から引き出される最後のレコードのコンマを削除する必要があります。
ありがとうございました