把生活写成首诗
2020-04-01 10:21
采纳率: 68.4%
浏览 530

C#中DataGridView怎么显示List集合中个别数据

   public List<teache> getteacherdata()
       {
           List<teache> te = new List<teache>();
           string sql = "select * from teacher";
           var reader = SqlDBHelper.ExecuteReader(sql);
           while (reader.Read())
           {
               teache tea = new teache();
               tea.Logid = Convert.ToInt32(reader["username"]); ;
               tea.Logpwd = Convert.ToInt32(reader["password"]);
               tea.Name = Convert.ToString(reader["name"]);
               tea.Gender = Convert.ToString(reader["gender"]);
               tea.Faculty = Convert.ToString(reader["faculty"]);
               tea.Phone = Convert.ToInt32(reader["telephone"]);
               tea.Title = Convert.ToString(reader["title"]);
               tea.Direction = Convert.ToString(reader["direction"]);
               tea.Digest = Convert.ToString(reader["digest"]);


               te.Add(tea);
           }
           return te;
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • threenewbee 2020-04-01 10:24
    已采纳

    比如说只显示男老师
    dataGridVew1.DataSource = getteacherdata().Where(x => x.Gender == "男").ToList();
    只显示前5条记录
    dataGridVew1.DataSource = getteacherdata().Take(5).ToList();

    打赏 评论

相关推荐 更多相似问题