学生表(student :姓名,性别,年龄,班级)请使用Linq实现对学生集合根据性别进行分组排序
展开全部
public void ToSql1()
{
string connectsql = "server=.\\SQLEXPRESS;database=test;uid=zy;pwd=zy;";//sql 验证
string connectwin = "server=.\\sqlexpress;database=test;integrated security=true;";//windows 验证
DataContext d = new DataContext(connectwin);
Table<Student> std = d.GetTable<Student>();
//根据性别分组查询
var val = from s in std group s by s.Sex into g select g;
foreach (var s in val)
{
txtPrint.AppendText(s.First().Sex, ":");
foreach (var s1 in s)
{
txtPrint.AppendText(s1.Name, new string[] { s1.Sex, s1.Age.S() });
}
txtPrint.AppendText("\r\n");
}
}
{
string connectsql = "server=.\\SQLEXPRESS;database=test;uid=zy;pwd=zy;";//sql 验证
string connectwin = "server=.\\sqlexpress;database=test;integrated security=true;";//windows 验证
DataContext d = new DataContext(connectwin);
Table<Student> std = d.GetTable<Student>();
//根据性别分组查询
var val = from s in std group s by s.Sex into g select g;
foreach (var s in val)
{
txtPrint.AppendText(s.First().Sex, ":");
foreach (var s1 in s)
{
txtPrint.AppendText(s1.Name, new string[] { s1.Sex, s1.Age.S() });
}
txtPrint.AppendText("\r\n");
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询