Create a comma delimited list

Settembre 25th, 2007

Description: This converts rows returned from a reader into a comma-delimited string.

Link: http://www.codekeep.net/snippets/07df10fa-37c2-4a2e-8bb1-b26c55cecc05.aspx

        private string GetCommaDelimitedList(IDataReader reader)
        {
            string list = string.Empty;
            StringBuilder sb = new StringBuilder();

            while (reader.Read())
                sb.AppendFormat(",{0}", reader[0]);

            if (sb.Length > 0)
                list = sb.ToString(1, sb.Length - 1);

            return list;
        }

  • .NET
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Trackback URI | Comments RSS

Leave a Reply

You must be logged in to post a comment.