作业帮 > 综合 > 作业

c#中如何使用带过滤条件的查询语句作为数据源

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/08/24 15:09:34
c#中如何使用带过滤条件的查询语句作为数据源
用Linq就可以啊.
例如有个表Student,有字段Name,Age,Gender
那么选出年龄大于20岁的学生
var stu=from student in students where student.Age>20 select new{姓名=student.Name,年龄=student.Age,性别=student.Gender}
然后绑定到数据源
this.datagridview1.DataSource=stu.ToList();