display several database entries in the same textbox?

Discussion in 'C#' started by BonaDrag, Aug 28, 2010.

  1. BonaDrag

    BonaDrag New Member

    Aug 28, 2010
    Likes Received:
    Trophy Points:
    I want to display all e-mail addresses from my database in a TextBox. The reason I want to use a TextBox is that I want them in a single row, separated by "; " and that's not possible in a ListBox (right?) which I was using from the beginning.

    So - I want to change my "display in ListBox"-code to "display in TextBox"-code. It doesn't seem to be enough just to change ListBox.Items.Add to TextBox.Text (as shown in code below), so what do I have to do to make it work (collect all addresses in an array first and then from there to the TextBox is a thought I'm having but maybe there's a better way)? The TextBox Mode is set to MultiLine.
     SqlConnection conn = new SqlConnection(config);
           string sql = "SELECT email FROM NewslttrRep";
           SqlCommand comm = new SqlCommand(sql, conn);
           SqlDataReader dr = comm.ExecuteReader();
           while (dr.Read())
               TextBoxEmailNewsletter.Text = (dr[0] + "; "); //only the last e-mail address in the database table is displayed

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice