Hi,I am very new to VB.NET and I need help with issue that I have. I have to make Last and First navigation buttons but I can't figure out the what to write. Here is my code:

Imports System.Data.OleDb
Public Class Form1
    Dim provider As String
    Dim dataFile As String
    Dim connString As String
    Dim myConnection As OleDbConnection = New OleDbConnection

    Private Sub btnPrev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrev.Click
        BindingContext(DataSet11, "students").Position = BindingContext(DataSet11, "students").Position + 1
    End Sub

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

    Private Sub btnNxt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNxt.Click
        BindingContext(DataSet11, "students").Position = BindingContext(DataSet11, "students").Position - 1
    End Sub

    Private Sub btnExt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExt.Click
        Me.Close()
    End Sub

    Private Sub btnUpd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpd.Click

    End Sub

    Private Sub btnDel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDel.Click
        BindingContext(DataSet11, "students").RemoveAt(BindingContext _
        (DataSet11, "students").Position)
    End Sub

    Private Sub btnClr_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClr.Click
        Me.txtIdNme.Text = ""
        Me.txtFrstNme.Text = ""
        Me.txtSur.Text = ""
        Me.txtGrp.Text = ""
        Me.txtBal.Text = ""
        Me.txtDate.Text = ""
    End Sub

    Private Sub btnSve_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSve.Click
        provider = "Provider = Microsoft.ACE.OLEDB.12.);Data Source = C:\Users\Nuri\Desktop\ABC.accdb"
        dataFile = "C:\Users\Nuri\Desktop\ABC.accdb"
        connString = provider & dataFile
        myConnection.ConnectionString = connString

        myConnection.Open()
        Dim str As String
        str = "insert into students ([ID Number] , [First Name], [Surname], [Amount], [Date] values (? , ? , ?)"
        Dim cmd As OleDbCommand = New OleDbCommand(str, myConnection)
        cmd.Parameters.Add(New OleDbParameter("ID Number", CType(txtIdNme.Text, String)))
        cmd.Parameters.Add(New OleDbParameter("First Name", CType(txtFrstNme.Text, String)))
        cmd.Parameters.Add(New OleDbParameter("Surname", CType(txtSur.Text, String)))
        cmd.Parameters.Add(New OleDbParameter("Amount", CType(txtBal.Text, String)))
        cmd.Parameters.Add(New OleDbParameter("Date", CType(txtDate.Text, String)))
        Try
            cmd.ExecuteNonQuery()
            cmd.Dispose()
            myConnection.Close()
            txtIdNme.Clear()
            txtFrstNme.Clear()
            txtSur.Clear()
            txtBal.Clear()
            txtDate.Clear()
        Catch ex As Exception
            MsgBox(ex.Message)
            myConnection.Close()
        End Try

    End Sub

    Private Sub btnFrst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFrst.Click

    End Sub
End Class

It depends how you are handling the data but, for example, if you were pulling each record from the database as it was needed your first and last buttons would be queries that extracted the first and last matching record respectively - use order by asc/desc limit 1 (for mysql) to get the single record.
If you have the records stored in some form of data store then you just need to access index 0 or index length - 1.
BindingContext(DataSet11, "students").Position = 0
or
BindingContext(DataSet11, "students").Position = DataSet11.Rows.Count - 1

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.