我正在使用C#执行一个“while”循环,这个循环遍历从数据库中检索出来的一些记录。如何最好地检测/查找循环中的最后一条记录?这可能吗?
这是我的代码:
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("],");",我需要删除从数据库中获取的最后一条记录上的逗号。
谢谢
SqlDataReader
。 - Oded@"\foo..."
- gdoron