Question

this code adds only the first line, how do I add the second line of the column "mail"

var cs = ConfigurationManager.ConnectionStrings["ConnectionString"];
        var sc = new SqlConnection(cs.ConnectionString);
        sc.Open();
        string str = "Select * From [Table1]";
        var cmd = new SqlCommand(str, sc);

        SqlDataReader dr = cmd.ExecuteReader();
        if (dr.Read())
        {
            ListBox1.Items.Add(dr["mail"].ToString());
        }
        sc.Close();
Was it helpful?

Solution

 if (dr.HasRows)
    {
    while (dr.Read())
    {
        /* your code */
    }
   }
  else
    {
     /* error message */
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top