VBNET数据库编程基础教程(17)
发布时间:2021-06-07
发布时间:2021-06-07
Private Sub btnEnd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnd.Click
Me.BindingContext(myDataSet, ″student″).Position = Me.BindingContext(myDataSet, ″student″).Count - 1
End Sub
(4)翻阅到第一条记录:
双击“第一条记录”按钮,在代码窗中输入以下代码:
Private Sub btnFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFirst.Click
Me.BindingContext(myDataSet, ″student″).Position = 0
End Sub
说明:为了代码书写方便,我们可以先定义一个BindingManagerBase对象myBind,如myBind = Me.BindingContext (myDataSet, ″student″ ),于是以上各句代码均可以简写成:
向上翻阅一条记录:myBind.Position = myBind.Position - 1
向下翻阅一条记录:myBind.Position = myBind.Position + 1
翻阅到最后一条记录:myBind.Position=myBind.count - 1
翻阅到第一条记录:myBind.Position = 0
2.删除数据记录
双击“删除记录”按钮,在代码窗中输入以下代码:
Private Sub btnDel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDel.Click
Dim ConnectionString As String = ″ Provider = Microsoft.Jet.OLEDB.4.0; Data Source = e:\My Documents\db1.mdb″
Dim myConn As OleDbConnection = New OleDbConnection()
myConn.ConnectionString = ConnectionString
myConn.Open()
上一篇:国内养老地产发展模式研究