문제

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