|
Free
C# Tutorials
|
![]() |
home |
Stay
at Home and Learn
|
|||||
How to Move to the First and Last Record in a Datase |
||||||
|
<< Part of an ongoing lesson - first part is here >>
Jump to the Last Record in your DatabaseTo move to the last record of your database, you only need to make sure that the inc variable and MaxRows have the same value. Add a new button to your form. Set the Text property as Last Record, and the Name property as btnLast. Double click, and add the following code:
The If Statement again checks that inc is not equal to MaxRows minus 1. If it isn't, we have this: inc = MaxRows - 1; MaxRows minus 1 would equal 3 in our four record database. Because Rows[inc] goes from 0 to 3, this is enough to move to the last record after the call to NavigateRecords. Here's what your form should look like, when you test it out and click your new button:
Jump to the First Record in your DatabaseTo move to the first record in the database, we only need to set inc to zero. Add another button to your form. Change the Text property to First
Record. Change the Name property to btnFirst. Double click
your new button and add the following code:
This just checks to see if inc isn't already zero. If it isn't, we set the inc variable to 0. Then we call the NavigateRecords method. When you test out your new button, your form should look like this:
You should now be able to move through the records in your database without the programme crashing. What we'll do now is to allow the user to add a new record to the database. This is more complex than the navigation, so you may need to pay close attention! <-- Move Previous | Add a New Record --> <--Back to the C# .NET Contents Page View all our Home Study Computer Courses
|