antiblock
Rodnia | Alpha & Omega
  • Chatbox

    You don't have permission to chat.
    Load More
Bergalho

Ajuda Relacionado com base de dados -

1 post in this topic

Boas . 

Tenho um trabalho aqui que não está a funcionar na perfeição , é um género de registo incluindo uma base de dados criada no microsoft access que não atualiza mediante os dados inseridos no programa . 

Desde já mando aí o código : 

Public Class frmPrincipal
    Dim identificador As Integer = 1
    Private Sub frmPrincipal_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.PessoaTableAdapter.Fill(Me.RegistoDataSet.Pessoa)

    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        PessoaBindingSource.MoveNext()

    End Sub

    Private Sub butAnterior_Click(sender As Object, e As EventArgs) Handles butAnterior.Click
        PessoaBindingSource.MovePrevious()
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        txtNome.Clear()
        txtIdade.Clear()
        identificador = 0
        txtNome.Focus()

    End Sub

    Private Sub butOk_Click(sender As Object, e As EventArgs) Handles butOk.Click
        Try
            If (identificador = 0) Then
                PessoaTableAdapter.PessoaInsertQuery(txtNome.Text, Integer.Parse(txtIdade.Text))
            Else
                Dim linha As RegistoDataSet.PessoaRow = RegistoDataSet.Pessoa.Rows(PessoaBindingSource.Position)
                Dim código As Integer = linha.Código
                PessoaTableAdapter.PessoaUpdateQuery(txtNome.Text, Integer.Parse(txtIdade.Text), código)
            End If
        Catch excep As DataException
            MessageBox.Show(excep.Message, "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        End Try
        identificador = 1
        Me.PessoaTableAdapter.Fill(RegistoDataSet.Pessoa)
    End Sub

    Private Sub butApagar_Click(sender As Object, e As EventArgs) Handles butApagar.Click
        Try
            Dim linha As RegistoDataSet.PessoaRow = RegistoDataSet.Pessoa.Rows(PessoaBindingSource.Position)
            Dim código As Integer = linha.Código
            PessoaTableAdapter.PessoaDeleteQuery(código)

        Catch excep As DataException
            MessageBox.Show(excep.Message, "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        End Try
        identificador = 1
        Me.PessoaTableAdapter.Fill(RegistoDataSet.Pessoa)
    End Sub
End Class
 

Share this post


Link to post
Share on other sites
antiblock
Elveron

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now