同济大学数据库作业

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 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))
Binding("text", mybind, "telephone", 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.完成学生成绩浏览功能的设计
Imports Class Form2
Dim mybind As New BindingSource
Dim mysql As String = "select * from shiyan8"
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 Form2_Load(sender As Object, e As EventArgs) Handles
(mydataset, "shiyan8")
= mydataset
= "shiyan8"
Binding("text", mybind, "snum", True))
Binding("text", mybind, "sname", True))
Binding("text", mybind, "cname", True))
Binding("text", mybind, "score", True))
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
()
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles
()
End Sub
End Class
三.实验体会或收获(有感而发,没有体会也可以不写)在用代码进行数据库的链接时发现data source后不能加(local),否则总是显示无法访问。

而如果写“jd43\SQLEXPRESS”
则可以进行访问。

用直接拖动的方法做出的和数据库的链接在不同的电脑上就不能正常运行,也是显示无法访问,然而用代码编写的链接只需要改动一下data source就可以继续访问。

虽然麻烦,但是感觉比较好用。

相关文档
最新文档