PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
VB database I can not delete a database record-VBForums
Results 1 to 5 of 5

Thread: VB database I can not delete a database record

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2017
    Posts
    2

    VB database I can not delete a database record

    VB database I can not delete a database record
    Please help me,
    the record is erased but when I open the software again the registration is there

    Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    'TODO: This line of code loads data into the 'Telef1DataSet.Tabel1' table. You can move, or remove it, as needed.
    Me.Tabel1TableAdapter.Fill(Me.Telef1DataSet.Tabel1)

    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Tabel1BindingSource.MovePrevious()
    End Sub

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
    Tabel1BindingSource.MoveNext()
    End Sub

    Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
    Tabel1BindingSource.AddNew()
    End Sub

    Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
    On Error GoTo SaveErr
    Validate()
    Tabel1BindingSource.EndEdit()
    Tabel1TableAdapter.Update(Telef1DataSet)
    MessageBox.Show("the person saved")
    SaveErr:
    End Sub

    Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
    If MsgBox("Delete this person ???", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
    Tabel1BindingSource.RemoveCurrent()
    MessageBox.Show("The person deleted !!!")
    End If
    End Sub
    Private Sub Button8_Click_1(sender As Object, e As EventArgs) Handles Button8.Click
    Close()
    End Sub
    End Class

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    100,631

    Re: VB database I can not delete a database record

    Firstly, please use appropriate formatting tags when posting code snippets, to aid readability.
    Quote Originally Posted by peter_g3 View Post
    VB database I can not delete a database record
    Please help me,
    the record is erased but when I open the software again the registration is there

    vb.net Code:
    1. Public Class Form1
    2.     Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    3.         'TODO: This line of code loads data into the 'Telef1DataSet.Tabel1' table. You can move, or remove it, as needed.
    4.         Me.Tabel1TableAdapter.Fill(Me.Telef1DataSet.Tabel1)
    5.  
    6.     End Sub
    7.  
    8.     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    9.         Tabel1BindingSource.MovePrevious()
    10.     End Sub
    11.  
    12.     Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
    13.         Tabel1BindingSource.MoveNext()
    14.     End Sub
    15.  
    16.     Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
    17.         Tabel1BindingSource.AddNew()
    18.     End Sub
    19.  
    20.     Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
    21.         On Error GoTo SaveErr
    22.         Validate()
    23.         Tabel1BindingSource.EndEdit()
    24.         Tabel1TableAdapter.Update(Telef1DataSet)
    25.         MessageBox.Show("the person saved")
    26. SaveErr:
    27.     End Sub
    28.  
    29.     Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
    30.         If MsgBox("Delete this person ???", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
    31.             Tabel1BindingSource.RemoveCurrent()
    32.             MessageBox.Show("The person deleted !!!")
    33.         End If
    34.     End Sub
    35.     Private Sub Button8_Click_1(sender As Object, e As EventArgs) Handles Button8.Click
    36.         Close()
    37.     End Sub
    38. End Class
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    100,631

    Re: VB database I can not delete a database record

    The code you have in the Button6 Click event handler is not deleting anything from the database. All it is actually doing is flagging the row as deleted in the DataSet. You have to actually commit that change back to the database separately. That's exactly what this line of code does, which you have elsewhere:
    vb.net Code:
    1. Tabel1TableAdapter.Update(Telef1DataSet)
    That's the code that commits all the changes in that DataTable back to the database. Normally, you'll let the user make as many changes as they want -adding, editing and deleting - and then save the lot in a single batch. If you want to save immediately after each change then you need to call that Update method after each change.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    100,631

    Re: VB database I can not delete a database record

    I also feel compelled to point out that it is very bad that you have simply accepted the default names for everything. If I do a demo or a quick test then I'll tend to accept names like Button1 and TextBox1. There's no way I'd ever have a control named Button8 though. If I've got eight Buttons, I'm giving them descriptive names that indicate their purpose and make distinguishing them easy.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    New Member
    Join Date
    Jul 2017
    Posts
    2

    Re: VB database I can not delete a database record

    thanks for all the answers

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width