none
looop through record then put all in a string RRS feed

  • Question

  • i have this select query that select the user name in the database table. This table has 10 users. So i want it to read all the record, then put everything in a string. How do i do that?

    EX: "John, Boo, Bob, ......" (like this)

    Can anyone help?

    what i have so far is

    while rs.read

         str = rs.getvalues(i)

         i = i + 1

    end while

    but this keeps giving me error of array out of bound
    Monday, July 23, 2007 7:04 PM

All replies

  • I'm shooting from the hip a little bit on this one because I don't know enough about your data... but I think your code should look something like this:

     

    Code Snippet

    Dim strComma As String = String.Empty

    Dim str      As String = String.Empty

     

    While (rs.Read())

       str += strComma + rs.GetString(rs.GetOrdinal("UserName"))

       strComma = ","

    End While

     

     If you replace "UserName" with the column name that has the information you want, it should work.

     

    A little more effecient way to do the code above, would be to store the oridinal value of the column in a variable (because that shouldn't change throughout the life of your loop).  That way you aren't doing a column lookup everytime around the loop.

     

     

    Monday, July 23, 2007 11:59 PM