我在 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("],");" 我需要删除从数据库中提取的最后一条记录上的逗号。
谢谢你