同济大学数据库作业lab7,8
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
同济大学
《数据库技术及应用》
实验报告
实验报告题目:
建立与数据库的链接和基于绑定的数据库访问
姓名:学号:
年级:专业:
指导教师:
日期: 2014 年 11 月 16 日一.实验目的
1.掌握数据库访问模型的主要对象和功能
2.掌握SQL和数据库的链接方法
3.学习绑定对象的操作方法
二.实验内容
(实验题目+运行界面截图+实现代码)
1.掌握前台和SqlServer后台的链接方法
Imports Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles
Dim myconn As New SqlConnection("database=university;data source=jd43\SQLEXPRESS; integrated security=true")
Dim mysql As String = "select * from student"
Dim myadapter As New SqlDataAdapter(mysql, myconn)
Dim mydataset As New DataSet
(mydataset, "student")
= (0)
End Sub
End Class
2.在university上用完成如下界面
Imports Class Form2
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles
Dim myconn As New SqlConnection("database=university;data source=jd43\SQLEXPRESS; integrated security=true")
Dim mysql As String = "select as '学号',sname as '姓名',count(secnum) as '选修课程门数',avg(score) as '平均成绩',sum(1-score/60) as '不及格门数' from student,sc where = group by ,sname"
Dim myadapter As New SqlDataAdapter(mysql, myconn)
Dim mydataset As New DataSet
(mydataset, "student")
= (0)
End Sub
End Class
3.建立university和student的浏览界面
Imports Class Form1
Dim mybind As New BindingSource
Dim mysql As String = "select * from student"
Dim myconn As New SqlConnection("database=university;data source=jd43\SQLEXPRESS;integrated security=true")
Dim myadapter As New SqlDataAdapter(mysql, myconn)
Dim mydataset As New DataSet
Private Sub退出系统ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles退出系统End
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles
(mydataset, "student")
= mydataset
= "student"
Binding("text", mybind, "snum", True))
Binding("text", mybind, "sname", True))
Binding("text", mybind, "sex", True))
Binding("text", mybind, "dept", True))
Binding("text", mybind, "birthday", True))
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles ()
End Sub
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles ()
End Sub
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles ()
End Sub
Private Sub Button7_Click(sender As Object, e As EventArgs) Handles ()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles ()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles ()
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles ()
()
Dim cm As New SqlCommandBuilder(myadapter)
(0))
End Sub
End Class
4.完成学生成绩浏览功能的设计