caramelo123 Posted May 15, 2014 at 11:54 AM Report #555752 Posted May 15, 2014 at 11:54 AM Boas, estou com um problema a remover um registo da base de dados em access e do próprio programa. Problema: Quando clico no botão de remover não consigo mexer em nada, só carregando no botão "stop debuggind", e não remove nada. Meti tambem o codigo do 1º formulario que de momento está a funcionar corretamente Public Class Form1 Dim c As String Dim op As Char Dim op1, op2 As String Private Sub Button21_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button21.Click Form2.Show() End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'TODO: This line of code loads data into the 'DatabaseDataSet.dados' table. You can move, or remove it, as needed. Me.DadosTableAdapter.Fill(Me.DatabaseDataSet.dados) Me.DadosTableAdapter.Fill(Me.DatabaseDataSet.dados) DadosBindingSource.AddNew() Me.TableAdapterManager.UpdateAll(Me.DatabaseDataSet) End Sub Private Sub Button18_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button18.Click op2 = Val(c) If op = "/" Then ResultadoTextBox.Text = Val(op1) / Val(op2) ValoresTextBox.Text = op1 & "/" & op2 End If If op = "*" Then ResultadoTextBox.Text = Val(op1) * Val(op2) ValoresTextBox.Text = op1 & "*" & op2 End If If op = "+" Then ResultadoTextBox.Text = Val(op1) + Val(op2) ValoresTextBox.Text = op1 & "+" & op2 End If If op = "-" Then ResultadoTextBox.Text = Val(op1) - Val(op2) ValoresTextBox.Text = op1 & "-" & op2 End If Me.Validate() Me.DadosBindingSource.EndEdit() Me.TableAdapterManager.UpdateAll(Me.DatabaseDataSet) End Sub Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button16.Click ValoresTextBox.Clear() c = "" End Sub Private Sub Button20_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button20.Click DadosBindingSource.RemoveAt(DadosBindingSource.Position) Me.TableAdapterManager.UpdateAll(Me.DatabaseDataSet) End Sub Private Sub Button17_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button17.Click DadosBindingSource.AddNew() Me.TableAdapterManager.UpdateAll(Me.DatabaseDataSet) End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click c = c & 1 ValoresTextBox.Text = c End Sub Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click op1 = c ValoresTextBox.Clear() c = "" op = "/" End Sub Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click op1 = c ValoresTextBox.Clear() c = "" op = "*" End Sub Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Click op1 = c ValoresTextBox.Clear() c = "" op = "+" End Sub Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click op1 = c ValoresTextBox.Clear() c = "" op = "-" End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click c = c & 2 ValoresTextBox.Text = c End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click c = c & 3 ValoresTextBox.Text = c End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click c = c & 4 ValoresTextBox.Text = c End Sub Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click c = c & 5 ValoresTextBox.Text = c End Sub Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click c = c & 6 ValoresTextBox.Text = c End Sub Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click c = c & 7 ValoresTextBox.Text = c End Sub Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click c = c & 8 ValoresTextBox.Text = c End Sub Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) c = c & 9 ValoresTextBox.Text = c End Sub Private Sub Button22_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button22.Click Dim x As Single x = MsgBox("Quer mesmo sair?", MsgBoxStyle.YesNo, "Sair") If x = vbYes Then Close() End If End Sub Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click c = c & 0 ValoresTextBox.Text = c End Sub Private Sub DadosBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Me.Validate() Me.DadosBindingSource.EndEdit() Me.TableAdapterManager.UpdateAll(Me.DatabaseDataSet) End Sub End Class Public Class Form2 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Me.Validate() Me.DadosBindingSource.EndEdit() Me.TableAdapterManager.UpdateAll(Me.DatabaseDataSet) Me.Close() End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Me.Validate() Me.DadosBindingSource.EndEdit() Me.TableAdapterManager.UpdateAll(Me.DatabaseDataSet) Dim x As Single x = MsgBox("Quer mesmo sair?", MsgBoxStyle.YesNo, "Sair") If x = vbYes Then Close() Form1.Close() End If End Sub Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'TODO: This line of code loads data into the 'DatabaseDataSet.dados' table. You can move, or remove it, as needed. Me.DadosTableAdapter.Fill(Me.DatabaseDataSet.dados) 'TODO: This line of code loads data into the 'DatabaseDataSet.dados' table. You can move, or remove it, as needed. Me.DadosTableAdapter.Fill(Me.DatabaseDataSet.dados) Me.TableAdapterManager.UpdateAll(Me.DatabaseDataSet) Label1.Text = ValoresListBox.Items.Count End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click ValoresListBox.SelectedItem. DadosBindingSource.RemoveAt(DadosBindingSource.Position) Me.TableAdapterManager.UpdateAll(Me.DatabaseDataSet) End Sub End Class
nelsonr Posted May 15, 2014 at 12:54 PM Report #555766 Posted May 15, 2014 at 12:54 PM O remover é em que botão? no 3? Ja fizeste debug para ver em que linha para?
killerbest Posted May 15, 2014 at 01:09 PM Report #555769 Posted May 15, 2014 at 01:09 PM Dim rowToDelete As Int32 = Me.basededados.Rows.GetFirstRow( _ DataGridViewElementStates.Selected) If rowToDelete > -1 Then Me.basededados.Rows.RemoveAt(rowToDelete) End If Esse codigo eu uso para uma datagrid veja se consegue adaptar
caramelo123 Posted May 16, 2014 at 07:43 AM Author Report #555878 Posted May 16, 2014 at 07:43 AM O remover é em que botão? no 3? Ja fizeste debug para ver em que linha para? Sim, é no botão 3.
caramelo123 Posted May 16, 2014 at 08:20 AM Author Report #555882 Posted May 16, 2014 at 08:20 AM Dim rowToDelete As Int32 = Me.basededados.Rows.GetFirstRow( _ DataGridViewElementStates.Selected) If rowToDelete > -1 Then Me.basededados.Rows.RemoveAt(rowToDelete) End If Esse codigo eu uso para uma datagrid veja se consegue adaptar Não estou a conseguir utilizar o codigo, mas obrigado por tentar.
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