qq_40746832
把生活写成首诗
采纳率62.5%
2020-04-01 10:21

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

5
已采纳
   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条回答

  • caozhy 回答这么多问题就耍赖把我的积分一笔勾销了 1年前

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

    点赞 1 评论 复制链接分享