同济大学数据库实验八

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

一、实验目的

1.掌握的数据库访问方法。

2.学习绑定对象的操作方法。

二、实验内容

(实验题目+运行界面截图+实现代码)

方法一代码:(注:红色字体为输入的代码)

Imports System.Data.SqlClient

Public Class Form1

Inherits System.Windows.Forms.Form

Public mybind As BindingManagerBase

Private Sub StudentBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StudentBindingNavigatorSaveItem.Click

Me.Validate()

Me.StudentBindingSource.EndEdit()

Me.TableAdapterManager.UpdateAll(Me.UniversityDataSet) End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

'TODO: 这行代码将数据加载到表“UniversityDataSet.student”中。您可以根据需要移动或移除它。

Me.StudentTableAdapter.Fill(Me.UniversityDataSet.student)

mybind = Me.BindingContext(StudentBindingSource) End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

mybind.Position = 0

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

mybind.Position = mybind.Position - 1

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

mybind.Position = mybind.Position + 1

End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click

mybind.Position = mybind.Count - 1

End Sub

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click

mybind.AddNew()

End Sub

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click

mybind.RemoveAt(mybind.Position)

End Sub

Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click

Validate()

StudentBindingSource.EndEdit()

TableAdapterManager.UpdateAll(Me.UniversityDataSet) End Sub

Private Sub退出系统ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles退出系统ToolStripMenuItem.Click

End

End Sub

End Class

方法二代码:(注:红色字体为输入的代码)

Public Class Form1

Private Sub StudentBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StudentBindingNavigatorSaveItem.Click

Me.Validate()

Me.StudentBindingSource.EndEdit()

Me.TableAdapterManager.UpdateAll(Me.UniversityDataSet)

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

'TODO: 这行代码将数据加载到表“UniversityDataSet.student”中。您可以根据需要移动或移除它。

Me.StudentTableAdapter.Fill(Me.UniversityDataSet.student) End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

StudentBindingSource.MoveFirst()

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

StudentBindingSource.MovePrevious()

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

StudentBindingSource.MoveNext()

End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click

StudentBindingSource.MoveLast()

End Sub

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click

StudentBindingSource.AddNew()

End Sub

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click

StudentBindingSource.RemoveCurrent()

End Sub

Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click

Validate()

StudentBindingSource.EndEdit()

TableAdapterManager.UpdateAll(Me.UniversityDataSet) End Sub

Private Sub退出系统ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles退出系统ToolStripMenuItem.Click

End

End Sub

End Class

相关文档
最新文档