Creating database applications in VB-Part II
In Lesson 23, you have learned how to create a simple database application using data control. However, you could only browse the database using the data control. In this lesson, you shall learn how to create your own navigation buttons for browsing the database. Besides that, we shall also learn how to add, save and delete data.The data control support some methods that allows manipulation of database, for example, to move the pointer to a certain location.
The following are some of
the commands that you can use to move the pointer around:
' Move to the first recorddata_navigator.RecordSet.MoveFirst' Move to the last recorddata_navigator.RecordSet.MoveLast' Move to the next recorddata_navigator.RecordSet.MoveNext' Move to the first recorddata_navigator.RecordSet.Previous
data_navigator.RecordSet.AddNew ' Adds a new record*note: data_navigator is the name of data control
data_navigator.RecordSet.Update ' Updates and saves the new record
data_navigator.RecordSet.Delete ' Deletes a current record
In the following example, you shall insert four commands and label them as First Record, Next Record, Previous Record and Last Record . They will be used to navigator around the database without using the data control. You still need to retain the same data control (from example in lesson 19) but set the property Visible to no so that users will not see the data control but use the button to browse through the database instead. Now, double-click on the command button and key in the codes according to the labels.
Private Sub cmdFirst()
data_navigator.Recordset.MoveFirst
End Sub
Private Sub cmdFirst_Click()
data_navigator.Recordset.MoveNext
End Sub
Private Sub cmdPrevious_Click()
data_navigator.Recordset.MovePrevious
End Sub
Private Sub cmdLast_Click()
data_navigator.Recordset.MoveLast
End Sub
Run the application and you shall obtain the interface as shown in Figure 24.1 below and you will be
able to browse the database using the four navigation buttons.
0 comments:
Post a Comment