|
-
Aug 8th, 2002, 07:48 AM
#1
Thread Starter
New Member
Delete Item from Listbox connected to Access DB (>Code)
Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
'**** Connection to Acces DB
Dim MyConnection As OleDbConnection
MyConnection = New OleDbConnection()
MyConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Inetpub\wwwroot\DataManipulatingTest\dbVoetbal.mdb;Persist Security Info=False"
MyConnection.Open()
'**** Filling DataSet
Dim DSPloegen As New DataSet()
Dim commPloeg As New OleDbDataAdapter()
Dim selectCMD As OleDbCommand = New OleDbCommand("SELECT * FROM Ploegen WHERE Klasse = '1'", MyConnection)
commPloeg.SelectCommand = selectCMD
commPloeg.Fill(DSPloegen, "Ploegen")
'**** Deleting Row from DataSet and Refreshing listbox
Dim drRij As DataRow = DSPloegen.Tables("Ploegen").Rows(lstPloegNamen.SelectedIndex)
DSPloegen.Tables("Ploegen").Rows.Remove(drRij)
DSPloegen.AcceptChanges()
lstPloegNamen.Items.Clear()
lstPloegNamen.DataSource = DSPloegen.Tables("Ploegen")
lstPloegNamen.DataTextField = "Ploegnaam"
lstPloegNamen.DataBind()
MyConnection.Close()
End Sub
This is my code behind the DeleteButton.
Items are listed in a listbox.
With this code I can only delete 1 item.
Why?
Something wrong with my code?
Please help!
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
|