SqlCommand comm = new SqlCommand("select * from smallclass where bigclassid=" + nbigclassid+" order by smallclassid desc", conn);
        SqlDataReader adr = comm.ExecuteReader();
        string abcd = "";
        string defg = "";
        if (adr.Read())
        {
            while (adr.Read())
            {
                abcd = adr["smallclassid"].ToString().Trim() + "," + abcd;
                defg = adr["smallclassname"].ToString().Trim() + "," + defg;
            }
            Response.Write(abcd);
            Response.Write("<br>");
            adr.Close();
        }程序执行后,明明数据库中有三条记录,abcd字符串应该是"1,2,3,4,"
但是执行的结果却是"1,2,3,"
不知道是什么原因呢?

解决方案 »

  1.   

    SqlCommand comm = new SqlCommand("select * from smallclass where bigclassid=" + nbigclassid+" order by smallclassid desc", conn);
            SqlDataReader adr = comm.ExecuteReader();
            string abcd = "";
            string defg = "";
                while (adr.Read())
                {
                    abcd = adr["smallclassid"].ToString().Trim() + "," + abcd;
                    defg = adr["smallclassname"].ToString().Trim() + "," + defg;
                 Response.Write(abcd);
                Response.Write("<br>");
                }
                
                adr.Close();