c# - Fill generic list from SqlDataReader

前端 未结 5 1855
轮回少年
轮回少年 2021-02-14 02:23

How can I add values that a SqlDataReader returns to a generic List? I have a method where I use SqlDataReader to get CategoryID from a

5条回答
  •  温柔的废话
    2021-02-14 02:56

            List s = new List();
            conn.Open();
            SqlCommand command2 = conn.CreateCommand();
            command2.CommandText = ("select turn from Vehicle where Pagged='YES'");
            command2.CommandType = CommandType.Text;
            SqlDataReader reader4 = command2.ExecuteReader();
            while (reader4.Read())
            {
                s.Add(Convert.ToInt32((reader4["turn"]).ToString()));
            }
            conn.Close();
    

提交回复
热议问题