Hi, im developing a software in vb 2012 with a access 2010 local db, but for some reason i can´t remove records from the database. the following code breaks on line 6. i cant find the problem. the dataset is transmissoes and the the table is utilizador_avancado. can anyone help, i'm stuck

s = TextBox1.Text
                Dim itemFound As Integer = BindingSource1.Find("user", s)
                If itemFound <> -1 Then
                    Try
                        BindingSource1.Position = itemFound
                                Me.TransmissoesDataSet.Tables("utilizador_Avancado").Rows(itemFound).Delete()
                        Me.TransmissoesDataSet.AcceptChanges()
                        Me.Utilizador_AvancadoTableAdapter.Update(TransmissoesDataSet)
                        Me.Utilizador_AvancadoTableAdapter.ClearBeforeFill = True
                        Me.Utilizador_AvancadoTableAdapter.Fill(Me.TransmissoesDataSet.Utilizador_Avancado)
                        MsgBox("Utilizador Excluido com Sucesso", MsgBoxStyle.Information)
                    Catch ex As Exception
                        MsgBox("Erro ao Excluir Utilizador" + vbCrLf + " Base de Dados Inalterada", MsgBoxStyle.Critical)
                    End Try
                Else
                    MsgBox("O utilizador a excluir não foi encontrado", MsgBoxStyle.Critical)
                End If
            End If

I haven't had a chance to test this but I'm pretty sure you can ->Instead of deleting your record from the datatable. Me.TransmissoesDataSet.Tables("utilizador_Avancado").Rows(itemFound).Delete()

Remove the item from the BindingSource and call ResetBindings(False) Method.

 bs.RemoveAt(itemFound)
 bs.ResetBindings(False)

Then Accept changes method on the table. You should be able to use the Adapter Update then.

hi, the same thing happens, the dataset is not updated(does not remove the record), and the database does not change either. Here is the code with your input. THe code runs ok, no error on the try catch, but the record lives for ever :-)

 Dim s As String
                s = TextBox1.Text
                Dim itemFound As Integer = BindingSource1.Find("user", s)
                If itemFound <> -1 Then
                    Try
                        'Me.TransmissoesDataSet.Tables("utilizador Avancado").Rows(itemFound).Delete()
                        BindingSource1.RemoveAt(itemFound) ' your code
                        BindingSource1.ResetBindings(False)' your code
                        Me.TransmissoesDataSet.Utilizador_Avancado.AcceptChanges()
                        Me.Utilizador_AvancadoTableAdapter.Update(TransmissoesDataSet.Utilizador_Avancado)
                        Me.Utilizador_AvancadoTableAdapter.ClearBeforeFill = True
                        Me.Utilizador_AvancadoTableAdapter.Fill(Me.TransmissoesDataSet.Utilizador_Avancado)
                        MsgBox("Utilizador Excluido com Sucesso", MsgBoxStyle.Information)
                    Catch ex As Exception
                        MsgBox("Erro ao Excluir Utilizador" + vbCrLf + " Base de Dados Inalterada", MsgBoxStyle.Critical)
                    End Try
                Else
                    MsgBox("O utilizador a excluir não foi encontrado", MsgBoxStyle.Critical)
                End If

Does your DataAdapter have an Update Command Query Set? Also remove
BindingSource1.ResetBindings(False)

Does your ACCESS table have a Primary Key?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.