1.连接数据库
用sqlConnection连接SQL sever。数据库;OracleConnection类的对象连接Oracle数据库;OleDbConnection类的对象连接支持OLE DB的数据库,如Access;而OdbcConnection类的对象连接支持ODBC的数据库。与数据库的所有通讯最终都是通过connection对象来完成的。
2.数据库查询语句:
一.查询学生总人数
[code]Select count(SNo) from Student[/code]
二.查询选修课程的学生人数
[code]Select count(distinct sno)from sc[/code]
三.计算机1号课程的学生平均成绩
[code]Delect avg(score)from sc where cno=1[/code]
四.查询选修了3门以上课程的学生的学号
[code]Select sno
From sc
Group by sno
Having count (cno)>3[/code]
五.从学生选课数据库中查询选修课并且成绩在90分以上的学生名单
Select sname
From sc
Where cno=(select Cno from course where cname=‘数据库原理’)
And score>90
声明:此篇文档时来自于【狗刨学习网】社区-unity极致学院,是网友自行发布的Unity3D学习文章,如果有什么内容侵犯了你的相关权益,请与官方沟通,我们会即时处理。
3.调用查询功能
[code]Foreach(User u in list){
Console.WriteLine(u.ld+” ”+u.Name);
}
List<Users> list=select();
IEnumerator<User> it=list. GetEnumerator();
While(it.MoveNext()){
Console.WriteLine(it.Current.id+” ”+it.CURRENT.Name);
}[/code]