Ir para conteúdo
Fórum Script Brasil
  • 0

Os dados da tabela do access não aparecem no datagridview


Otacildo Ferreira da Silva

Pergunta

Bom dia amigos,

Sou iniciante em vb.net 2010, estou desenvolvendo um sistema para aprendizado e deparei com alguns problemas. Desde já agradeço a todos e desejo-lhes um Feliz Natal.

Banco de Dados: dB_Estoque.accdb

Tabela: tbl_Usuario

Cod_Usuario

Usu_Matricula

Usu_Nome

Usu_Dpto

Usu_Cargo

Usu_Email

Usu_Telefone

Usu_Usuario

Usu_Senha

Usu_Desativado

1 – Os dados não aparecem no datagridview.

2 – Não consigo resolver o problema do Carrega_Campos(). Na linha Dim ind As Integer = dgvUsuarios.CurrentRow.Index + 1 apresenta a mensagem "Referência de objeto não definida para uma instância de um objeto".

Imports System.Data.OleDb

Public Class frm_Usuario

Dim acod_Usuario(1) As Integer

Dim aMatricula(1) As String

Dim aNome(1) As String

Dim aDpto(1) As String

Dim aCargo(1) As String

Dim aEmail(1) As String

Dim aTelefone(1) As String

Dim aUsuario(1) As String

Dim aSenha(1) As String

Dim aDesativado(1) As String

Dim vModo As String = "x"

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

Carrega_Usuarios()

Habilita_Campos()

End Sub

Private Sub Carrega_Usuarios()

Dim cs As String = My.Settings.db_EstoqueConnectionString

Dim conect As New OleDb.OleDbConnection

conect.ConnectionString = cs

conect.Open()

Dim selcom As New OleDb.OleDbCommand

selcom.Connection = conect

selcom.CommandText = "SELECT * FROM tbl_Usuario ORDER BY usu_Nome"

Dim vLeitor As OleDb.OleDbDataReader

vLeitor = selcom.ExecuteReader()

Dim c As Integer = 0

dgvUsuarios.Rows.Clear()

Do While vLeitor.Read

c = c + 1

ReDim Preserve acod_Usuario©

ReDim Preserve aMatricula©

ReDim Preserve aNome©

ReDim Preserve aDpto©

ReDim Preserve aCargo©

ReDim Preserve aEmail©

ReDim Preserve aTelefone©

ReDim Preserve aUsuario©

ReDim Preserve aSenha©

ReDim Preserve aDesativado©

acod_Usuario© = vLeitor("cod_Usuario")

aMatricula© = vLeitor("usu_Matricula")

aNome© = vLeitor("usu_Nome")

aDpto© = vLeitor("usu_Dpto")

aCargo© = vLeitor("usu_Cargo")

aEmail© = vLeitor("usu_Email")

aTelefone© = vLeitor("usu_Telefone")

aUsuario© = vLeitor("usu_Usuario")

aSenha© = vLeitor("usu_Senha")

aDesativado© = vLeitor("usu_Desativado")

dgvUsuarios.Rows.Add(aNome©, aDpto©, aCargo©)

Loop

conect.Close()

End Sub

Private Sub Carrega_Campos()

Dim ind As Integer = dgvUsuarios.CurrentRow.Index + 1

txtMatricula.Text = aMatricula(ind)

txtNome.Text = aNome(ind)

txtDpto.Text = aDpto(ind)

txtCargo.Text = aCargo(ind)

txtEmail.Text = aEmail(ind)

txtTelefone.Text = aTelefone(ind)

txtUsuario.Text = aUsuario(ind)

txtSenha.Text = aSenha(ind)

'txtDesativado.Text = aDesativado(ind)

End Sub

Private Sub dgvUsuarios_SelectionChanged(sender As System.Object, e As System.EventArgs) Handles dgvUsuarios.SelectionChanged

Carrega_Campos()

End Sub

Private Sub btnAlterar_Click(sender As System.Object, e As System.EventArgs) Handles btnAlterar.Click

vModo = "A"

Habilita_Campos()

End Sub

Private Sub Habilita_Campos()

btnNovo.Enabled = False

btnAlterar.Enabled = False

btnExcluir.Enabled = False

btnConfirmar.Enabled = True

btnCancelar.Enabled = True

btnFechar.Enabled = False

txtMatricula.Enabled = True

txtNome.Enabled = True

txtDpto.Enabled = True

txtCargo.Enabled = True

txtEmail.Enabled = True

txtTelefone.Enabled = True

txtUsuario.Enabled = True

txtSenha.Enabled = True

'txtDestivado.Enabled = True

End Sub

Private Sub Desabilita_Campos()

btnNovo.Enabled = True

btnAlterar.Enabled = True

btnExcluir.Enabled = True

btnConfirmar.Enabled = False

btnCancelar.Enabled = False

btnFechar.Enabled = True

txtMatricula.Enabled = False

txtNome.Enabled = False

txtDpto.Enabled = False

txtCargo.Enabled = False

txtEmail.Enabled = False

txtTelefone.Enabled = False

txtUsuario.Enabled = False

txtSenha.Enabled = False

'txtDestivado.Enabled = False

End Sub

Private Sub btnCancelar_Click(sender As System.Object, e As System.EventArgs) Handles btnCancelar.Click

Desabilita_Campos()

Carrega_Campos()

End Sub

Private Sub btnConfirmar_Click(sender As System.Object, e As System.EventArgs) Handles btnConfirmar.Click

If vModo = "A" Then

Dim cs As String = My.Settings.db_EstoqueConnectionString

Dim conect As New OleDb.OleDbConnection

conect.ConnectionString = cs

Try

conect.Open()

Dim selcom As New OleDb.OleDbCommand

selcom.Connection = conect

selcom.CommandText = "UPDATE tbl_Usuario SET usu_Matricula= '" & txtMatricula.Text & "', usu_Nome= '" & txtNome.Text _

& "', usu_Dpto= '" & txtDpto.Text & "', usuCargo= '" & txtCargo.Text _

& "', usu_Email= '" & txtEmail.Text & "', usu_Telefone= '" & txtTelefone.Text _

& "', usu_Usuario= '" & txtUsuario.Text & "', usu_Senha= '" & txtSenha.Text & "' " _

& "WHERE usu_cod_Usuario = " & acod_Usuario(dgvUsuarios.CurrentRow.Index + 1)

selcom.ExecuteNonQuery()

conect.Close()

Catch ex As Exception

MessageBox.Show("Erro de gravação de dados!" & vbCrLf & ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)

End Try

Desabilita_Campos()

Carrega_Usuarios()

End If

If vModo = "I" Then

End If

If vModo = "E" Then

End If

End Sub

Private Sub btnNovo_Click(sender As System.Object, e As System.EventArgs) Handles btnNovo.Click

Habilita_Campos()

vModo = "I"

txtMatricula.Text = ""

txtNome.Text = ""

txtDpto.Text = ""

txtCargo.Text = ""

txtEmail.Text = ""

txtTelefone.Text = ""

txtUsuario.Text = ""

txtSenha.Text = ""

'txtDesativado.Text = ""

txtMatricula.Focus()

End Sub

Private Sub btnExcluir_Click(sender As System.Object, e As System.EventArgs) Handles btnExcluir.Click

Habilita_Campos()

vModo = "E"

End Sub

End Class

Link para o comentário
Compartilhar em outros sites

0 respostass a esta questão

Posts Recomendados

Até agora não há respostas para essa pergunta

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,1k
    • Posts
      651,8k
×
×
  • Criar Novo...