Вопрос

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();
Это было полезно?

Решение

 if (dr.HasRows)
    {
    while (dr.Read())
    {
        /* your code */
    }
   }
  else
    {
     /* error message */
    }
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top