Batista15 Posted April 22, 2009 at 10:53 AM Report #258198 Posted April 22, 2009 at 10:53 AM Eu tenho um código que serve para visualizar os dados sobre um cliente e nessa mesma form tenho uma picturebox para abrir outra form com a mesma informacao para eliminar, e quando elimino as forms fecham e quando abro a 1ª form o dado que eliminei ainda la aparece, queria que alguem me ajudasse em por exemplo fazer algo do tipo de actualizar... Form1 Imports System.Data.OleDb Imports System Imports System.Windows.Forms Imports System.Reflection Public Class Form16 Private Sub Form16_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim kk As New OleDbConnection(My.Settings.ligacao) ' LIGAR A BD kk.Open() ' ACESSO AOS DADOS Dim comandosqll = "SELECT Data, Valor_Glicemia,Tensao_Arterial_Sistolica,Tensao_Arterial_Diastolica FROM avaliacao where Id_Cliente = " & Form15.ListView1.SelectedItems.Item(0).SubItems(0).Text Dim cmdd As New OleDbCommand(comandosqll, kk) Dim ff As OleDbDataReader = cmdd.ExecuteReader(CommandBehavior.CloseConnection) DataGridView1.RowHeadersVisible = False ' CARREGAR OS DADOS Dim idx_linha As Integer idx_linha = 0 While ff.Read() Dim linha As New DataGridViewRow() DataGridView1.Rows.Add(linha) DataGridView1.Rows(idx_linha).Cells(0).Value = ff(0).ToString() DataGridView1.Rows(idx_linha).Cells(1).Value = ff(1).ToString() DataGridView1.Rows(idx_linha).Cells(2).Value = ff(2).ToString() DataGridView1.Rows(idx_linha).Cells(3).Value = ff(3).ToString() idx_linha = idx_linha + 1 End While ' FECHAR A BD ff.Close() End Sub Private Sub PictureBox9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox9.Click Form17.ShowDialog() End Sub End Class Form2 Imports System.Data.OleDb Imports System Imports System.Windows.Forms Imports System.Reflection Public Class Form17 Private Sub Form17_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim kk As New OleDbConnection(My.Settings.ligacao) ' LIGAR A BD kk.Open() ' ACESSO AOS DADOS Dim comandosqll = "SELECT Data, Valor_Glicemia,Tensao_Arterial_Sistolica,Tensao_Arterial_Diastolica,id_verificacao FROM avaliacao where Id_Cliente = " & Form15.ListView1.SelectedItems.Item(0).SubItems(0).Text Dim cmdd As New OleDbCommand(comandosqll, kk) Dim ff As OleDbDataReader = cmdd.ExecuteReader(CommandBehavior.CloseConnection) DataGridView1.RowHeadersVisible = False ' CARREGAR OS DADOS Dim idx_linha As Integer idx_linha = 0 While ff.Read() Dim linhas As New DataGridViewRow() DataGridView1.Rows.Add(linhas) DataGridView1.Rows(idx_linha).Cells(0).Value = ff(0).ToString() DataGridView1.Rows(idx_linha).Cells(1).Value = ff(1).ToString() DataGridView1.Rows(idx_linha).Cells(2).Value = ff(2).ToString() DataGridView1.Rows(idx_linha).Cells(3).Value = ff(3).ToString() DataGridView1.Rows(idx_linha).Cells(4).Value = ff(4).ToString() idx_linha = idx_linha + 1 End While ' FECHAR A BD ff.Close() End Sub Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick End Sub Private Sub DataGridView1_CellDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellDoubleClick Try Dim msg = MsgBox(" Deseja Eliminar o Cliente?", MsgBoxStyle.YesNo, "Apagar") If msg = MsgBoxResult.Yes Then Dim lm As String = "delete * from avaliacao where id_verificacao = " & DataGridView1.Rows(e.RowIndex).Cells(4).Value MsgBox("Avaliação eliminada!", MsgBoxStyle.Information, "Apagado") Me.Close() Form16.Close() ' Inicia uma ligação à bse de dados Using connection As New OleDbConnection(My.Settings.ligacao) ' Define o comando e os parâmetros Dim command As New OleDbCommand(lm, connection) ' Abre a ligação e insere o registo connection.Open() Dim x As Integer = command.ExecuteNonQuery() If x <> 1 Then Throw New ArgumentException("Não foi possível inserir o registo na base de dados!") 'Else End If End Using End If Catch ex As Exception MessageBox.Show(ex.Message, My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End Sub End Class
Luis Marques Posted April 22, 2009 at 10:55 AM Report #258200 Posted April 22, 2009 at 10:55 AM Tambem precisava disso! LM
José Lopes Posted April 22, 2009 at 11:02 AM Report #258202 Posted April 22, 2009 at 11:02 AM manda recarregar os dados no form 1..... Quando te pedirem peixe.... ensina-os a Pescar!!Hum..lálálálá!!
Weasel Posted April 22, 2009 at 01:01 PM Report #258232 Posted April 22, 2009 at 01:01 PM Tu estás a fechar os Forms antes de executar o código para apagar da base de dados. Mete isto no fim e não a meio: Me.Close() Form16.Close() Knowledge to the masses
Batista15 Posted April 22, 2009 at 01:11 PM Author Report #258236 Posted April 22, 2009 at 01:11 PM manda recarregar os dados no form 1..... Fazer o select depois daquilo? Tambem ja fiz e continua no mesmo
Batista15 Posted April 22, 2009 at 01:11 PM Author Report #258237 Posted April 22, 2009 at 01:11 PM Tu estás a fechar os Forms antes de executar o código para apagar da base de dados. Mete isto no fim e não a meio: Me.Close() Form16.Close() Tambem ja fiz e tambem nao da
debliu Posted April 22, 2009 at 01:21 PM Report #258242 Posted April 22, 2009 at 01:21 PM Solução 1: Ao carregar no botao Apagar mandas carregar a datagrid outra vez,ou seja, o mesmo que tens no load da form... Solução 2: (bah) Assim que apaga, fechas o form e mandas abrir outra vez... a 2 é muita ruim... =/ http://bolachas4.blogspot.com
Weasel Posted April 22, 2009 at 01:25 PM Report #258244 Posted April 22, 2009 at 01:25 PM E estás a apagar de facto da base de dados alguma coisa? verifica como está a ir a instrução SQL, mete um break nesta linha para veres as variáveis: Dim command As New OleDbCommand(lm, connection) Knowledge to the masses
Batista15 Posted April 22, 2009 at 01:40 PM Author Report #258253 Posted April 22, 2009 at 01:40 PM Solução 1: Ao carregar no botao Apagar mandas carregar a datagrid outra vez,ou seja, o mesmo que tens no load da form... Solução 2: (bah) Assim que apaga, fechas o form e mandas abrir outra vez... a 2 é muita ruim... =/ Já o fiz e não faz nada! Nao sei porqe 😛
Batista15 Posted April 22, 2009 at 01:41 PM Author Report #258254 Posted April 22, 2009 at 01:41 PM E estás a apagar de facto da base de dados alguma coisa? verifica como está a ir a instrução SQL, mete um break nesta linha para veres as variáveis: Dim command As New OleDbCommand(lm, connection) Sim apaga! Porque se eu fechar o programa todo e o voltar a abrir, ja apagou os dados
Hellblazer Posted April 22, 2009 at 02:00 PM Report #258259 Posted April 22, 2009 at 02:00 PM DataGridView1.DataSource = Nothing Preenches outra vez. DataGridView1.Rebind() Exprimenta e depois diz algo There are two ways to write error-free programs; only the third one works.
Batista15 Posted April 22, 2009 at 02:24 PM Author Report #258269 Posted April 22, 2009 at 02:24 PM DataGridView1.DataSource = Nothing Preenches outra vez. DataGridView1.Rebind() Exprimenta e depois diz algo Onde coloco cada uma desse codigo?
Hellblazer Posted April 22, 2009 at 02:53 PM Report #258280 Posted April 22, 2009 at 02:53 PM Depois de apagares There are two ways to write error-free programs; only the third one works.
Batista15 Posted April 22, 2009 at 02:57 PM Author Report #258282 Posted April 22, 2009 at 02:57 PM Depois de apagares Da-me erro: DataGridView1.Rebind()
Weasel Posted April 22, 2009 at 03:13 PM Report #258288 Posted April 22, 2009 at 03:13 PM Mas ele não tem a DataGridView com datasource nenhum... Experimenta assim (este ainda só actualiza a 2ª From (se correr tudo bem)) Imports System.Data.OleDb Imports System Imports System.Windows.Forms Imports System.Reflection Public Class Form17 Private Sub carrega_dados() Dim kk As New OleDbConnection(My.Settings.ligacao) ' LIGAR A BD kk.Open() ' ACESSO AOS DADOS Dim comandosqll = "SELECT Data, Valor_Glicemia,Tensao_Arterial_Sistolica,Tensao_Arterial_Diastolica,id_verificacao FROM avaliacao where Id_Cliente = " & Form15.ListView1.SelectedItems.Item(0).SubItems(0).Text Dim cmdd As New OleDbCommand(comandosqll, kk) Dim ff As OleDbDataReader = cmdd.ExecuteReader(CommandBehavior.CloseConnection) DataGridView1.Rows.Clear() DataGridView1.RowHeadersVisible = False ' CARREGAR OS DADOS Dim idx_linha As Integer idx_linha = 0 While ff.Read() Dim linhas As New DataGridViewRow() DataGridView1.Rows.Add(linhas) DataGridView1.Rows(idx_linha).Cells(0).Value = ff(0).ToString() DataGridView1.Rows(idx_linha).Cells(1).Value = ff(1).ToString() DataGridView1.Rows(idx_linha).Cells(2).Value = ff(2).ToString() DataGridView1.Rows(idx_linha).Cells(3).Value = ff(3).ToString() DataGridView1.Rows(idx_linha).Cells(4).Value = ff(4).ToString() idx_linha = idx_linha + 1 End While ' FECHAR A BD ff.Close() End Sub Private Sub Form17_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load carrega_dados() End Sub Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick End Sub Private Sub DataGridView1_CellDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellDoubleClick Try Dim msg = MsgBox(" Deseja Eliminar o Cliente?", MsgBoxStyle.YesNo, "Apagar") If msg = MsgBoxResult.Yes Then Dim lm As String = "delete * from avaliacao where id_verificacao = " & DataGridView1.Rows(e.RowIndex).Cells(4).Value MsgBox("Avaliação eliminada!", MsgBoxStyle.Information, "Apagado") ' Inicia uma ligação à bse de dados Using connection As New OleDbConnection(My.Settings.ligacao) ' Define o comando e os parâmetros Dim command As New OleDbCommand(lm, connection) ' Abre a ligação e insere o registo connection.Open() Dim x As Integer = command.ExecuteNonQuery() If x <> 1 Then Throw New ArgumentException("Não foi possível inserir o registo na base de dados!") 'Else End If End Using End If Catch ex As Exception MessageBox.Show(ex.Message, My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Error) End Try carrega_dados() End Sub End Class Knowledge to the masses
Batista15 Posted April 22, 2009 at 03:18 PM Author Report #258289 Posted April 22, 2009 at 03:18 PM Mas ele não tem a DataGridView com datasource nenhum... Experimenta assim (este ainda só actualiza a 2ª From (se correr tudo bem)) Imports System.Data.OleDb Imports System Imports System.Windows.Forms Imports System.Reflection Public Class Form17 Private Sub carrega_dados() Dim kk As New OleDbConnection(My.Settings.ligacao) ' LIGAR A BD kk.Open() ' ACESSO AOS DADOS Dim comandosqll = "SELECT Data, Valor_Glicemia,Tensao_Arterial_Sistolica,Tensao_Arterial_Diastolica,id_verificacao FROM avaliacao where Id_Cliente = " & Form15.ListView1.SelectedItems.Item(0).SubItems(0).Text Dim cmdd As New OleDbCommand(comandosqll, kk) Dim ff As OleDbDataReader = cmdd.ExecuteReader(CommandBehavior.CloseConnection) DataGridView1.Rows.Clear() DataGridView1.RowHeadersVisible = False ' CARREGAR OS DADOS Dim idx_linha As Integer idx_linha = 0 While ff.Read() Dim linhas As New DataGridViewRow() DataGridView1.Rows.Add(linhas) DataGridView1.Rows(idx_linha).Cells(0).Value = ff(0).ToString() DataGridView1.Rows(idx_linha).Cells(1).Value = ff(1).ToString() DataGridView1.Rows(idx_linha).Cells(2).Value = ff(2).ToString() DataGridView1.Rows(idx_linha).Cells(3).Value = ff(3).ToString() DataGridView1.Rows(idx_linha).Cells(4).Value = ff(4).ToString() idx_linha = idx_linha + 1 End While ' FECHAR A BD ff.Close() End Sub Private Sub Form17_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load carrega_dados() End Sub Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick End Sub Private Sub DataGridView1_CellDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellDoubleClick Try Dim msg = MsgBox(" Deseja Eliminar o Cliente?", MsgBoxStyle.YesNo, "Apagar") If msg = MsgBoxResult.Yes Then Dim lm As String = "delete * from avaliacao where id_verificacao = " & DataGridView1.Rows(e.RowIndex).Cells(4).Value MsgBox("Avaliação eliminada!", MsgBoxStyle.Information, "Apagado") ' Inicia uma ligação à bse de dados Using connection As New OleDbConnection(My.Settings.ligacao) ' Define o comando e os parâmetros Dim command As New OleDbCommand(lm, connection) ' Abre a ligação e insere o registo connection.Open() Dim x As Integer = command.ExecuteNonQuery() If x <> 1 Then Throw New ArgumentException("Não foi possível inserir o registo na base de dados!") 'Else End If End Using End If Catch ex As Exception MessageBox.Show(ex.Message, My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Error) End Try carrega_dados() End Sub End Class Funciona perfeitamente 😛 Obrigado E agora para a 1ª form?
Weasel Posted April 22, 2009 at 03:34 PM Report #258295 Posted April 22, 2009 at 03:34 PM Para a 1ª form Imports System.Data.OleDb Imports System Imports System.Windows.Forms Imports System.Reflection Public Class Form16 Private Sub carrega_dados() ' LIGAR A BD kk.Open() ' ACESSO AOS DADOS Dim comandosqll = "SELECT Data, Valor_Glicemia,Tensao_Arterial_Sistolica,Tensao_Arterial_Diastolica FROM avaliacao where Id_Cliente = " & Form15.ListView1.SelectedItems.Item(0).SubItems(0).Text Dim cmdd As New OleDbCommand(comandosqll, kk) Dim ff As OleDbDataReader = cmdd.ExecuteReader(CommandBehavior.CloseConnection) DataGridView1.Rows.Clear() DataGridView1.RowHeadersVisible = False ' CARREGAR OS DADOS Dim idx_linha As Integer idx_linha = 0 While ff.Read() Dim linha As New DataGridViewRow() DataGridView1.Rows.Add(linha) DataGridView1.Rows(idx_linha).Cells(0).Value = ff(0).ToString() DataGridView1.Rows(idx_linha).Cells(1).Value = ff(1).ToString() DataGridView1.Rows(idx_linha).Cells(2).Value = ff(2).ToString() DataGridView1.Rows(idx_linha).Cells(3).Value = ff(3).ToString() idx_linha = idx_linha + 1 End While ' FECHAR A BD ff.Close() End Sub Private Sub Form16_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim kk As New OleDbConnection(My.Settings.ligacao) carrega_dados() End Sub Private Sub PictureBox9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox9.Click Form17.ShowDialog() End Sub End Class Na Form17 terás de Acrescentar isto depois do "carrega_dados()" lá no fundo. Form16.carrega_dados() Knowledge to the masses
Batista15 Posted April 22, 2009 at 03:58 PM Author Report #258303 Posted April 22, 2009 at 03:58 PM Ja resolvi! Agora a parte dos Form16.carrega_dados() esta a dar problema onde o estou a a meter que e la mesmo no fundo como me disse A seguir ao carrega_dados() Foi como fiz
Weasel Posted April 22, 2009 at 04:40 PM Report #258319 Posted April 22, 2009 at 04:40 PM Que problema/Erro está a dar? Knowledge to the masses
Batista15 Posted April 22, 2009 at 07:11 PM Author Report #258353 Posted April 22, 2009 at 07:11 PM O erro e aquela linha azul, nao esta a dar! http://img16.imageshack.us/img16/6205/99928990.jpg
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now