在SQL Server 2005中查询数据,比如select name from students where age=22
得到的记录有若干条,比如有张三、李四、王五
怎么样才能把这些记录放到一个字符串中,成为strname=(张三,李四,王五)
急救!

解决方案 »

  1.   

    while (reader.Read())
    {
        strname += "," + reader.GetString(0);
    }
      

  2.   

    连接数据库后db.reader() 将每次读到的字符串+起来就可以了。
      

  3.   

    不行呀!出现错误的:无法将类型为“System.Int64”的对象强制转换为类型“System.String”。
      

  4.   

    那你Sql语句中第一个是name么
    while (reader.Read()) 

       strname += "," + reader.GetValue(0).ToString(); 
    }
    strname = strname.SubString(1);