-
Dec 8th, 2018, 02:15 AM
#1
Thread Starter
New Member
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
-
Dec 8th, 2018, 04:05 AM
#2
Re: VB database I can not delete a database record
Firstly, please use appropriate formatting tags when posting code snippets, to aid readability.
Originally Posted by peter_g3
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:
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
-
Dec 8th, 2018, 04:09 AM
#3
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:
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.
-
Dec 8th, 2018, 04:12 AM
#4
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.
-
Dec 8th, 2018, 04:53 AM
#5
Thread Starter
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|