none
VB 2010 Access Database Buttons Before and Next RRS feed

  • Pergunta

  • I have a form with a text box and two masked boxes. They show the name, cell phone and telephone that are stored in a registry of database Access 2007.

     

    The database have the fields Code (self numeration), Name, Telephone and Cell.

     

    When I execute the form, it shows the data in textbox and in masked boxes. They refer to the registry order by Name in alphabetical order.

     

    I would like that, when I click the buttons Next and Before, they show the content of the next and the before registry.

     

     

    I am starter and I ask you send me the codes that refer to the buttons next and before.

    Thank you.

    At the moment, my code is like this:

     

     

     

     

     

    Imports System.Data.OleDb

     

    Public Class frmAgenda

     

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

            Dim con As New OleDbConnection

            con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source='|DataDirectory|\Agenda Database.accdb'"

            con.Open()

            Dim comand As New OleDbCommand

            comand.CommandText = "SELECT TOP 1 * FROM tb_dados ORDER BY Name"

            comand.CommandType = CommandType.Text

            comand.Connection = con

     

            Dim reader As OleDbDataReader

            reader = comand.ExecuteReader()

           reader.Read()

            Me.txtNome.Text = reader("Nome").ToString

            Me.mskCelular.Text = reader("Cell").ToString

            Me.mskTelefone.Text = reader("Telephone").ToString

     

     

        End Sub

     

        Private Sub btnNext_Click(sender As System.Object, e As System.EventArgs) Handles btnNext.Click

     

            Dim con As New OleDbConnection

     

            con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source='|DataDirectory|\Agenda Database.accdb'"

     

            Dim comand As New OleDbCommand

     

        End Sub

     

     

        Private Sub btnBefore_Click(sender As System.Object, e As System.EventArgs) Handles btnBefore.Click

     

     


            Dim con As New OleDbConnection

     

            con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source='|DataDirectory|\Agenda Database.accdb'"

     

            Dim comand As New OleDbCommand

     

        End Sub

    End Class


    quinta-feira, 22 de dezembro de 2011 06:47

Respostas

  • Através da video aula 24 do curso Visual Basic Avançado da Treinamentos TI, aprendi que o código fica da seguinte forma:

     

     

     

    Private Sub btnProximo_Click(sender As System.Object, e As System.EventArgs) Handles btnProximo.Click

            Me.Tb_dadosBindingSource.MoveNext()

        End Sub


        Private Sub btnAnterior_Click(sender As System.Object, e As System.EventArgs) Handles btnAnterior.Click

            Me.Tb_dadosBindingSource.MovePrevious()

        End Sub

    sexta-feira, 23 de dezembro de 2011 04:33

Todas as Respostas