MarkItZero
Freshman
Ok,
This problem has been a real pain for me
I have a list box on a form which lists the UserNames in my DB(Access). I have a delete method which deletes the currently selected UserName from the DB. However, I cant seem to be able to get the listbox to properly refresh (ie not show the newly deleted UserName) For some reason, after I complete the delete method, the UserName still shows up in the listbox.
Here is my code:
I hope that code is readable.
Any suggestions?
Thanks!
[edit]it's more readable with
This problem has been a real pain for me
I have a list box on a form which lists the UserNames in my DB(Access). I have a delete method which deletes the currently selected UserName from the DB. However, I cant seem to be able to get the listbox to properly refresh (ie not show the newly deleted UserName) For some reason, after I complete the delete method, the UserName still shows up in the listbox.
Here is my code:
Visual Basic:
'Populate LstUsers
Sub PopulateLstUsers()
'Fill Dataset
OleDbDataAdapter1.Fill(DsEditUsers1, "Users")
'Declare Array
Dim ArryEditUsers As ArrayList = New ArrayList()
Dim RowEditUsers As DataRow
'Fill Array
For Each RowEditUsers In DsEditUsers1.Tables("Users").Rows
ArryEditUsers.Add(New LookupItem(RowEditUsers("UserID"), RowEditUsers("UserName").ToString()))
Next
'Fill List
If ArryEditUsers.Count > 0 Then
lstUsers.DataSource = ArryEditUsers
lstUsers.DisplayMember = "Text"
lstUsers.ValueMember = "ID"
End If
'Declare LookupItem
Dim li As LookupItem
'Fill LookupItem
li = DirectCast(lstUsers.SelectedItem, LookupItem)
'Display List
DisplayUserInfo(li.ID)
End Sub
'Display User Info
Sub DisplayUserInfo(ByVal ID as Integer)
'Display other columns from record in textboxes
End Sub
'Click Delete
Private Sub CmdDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdDelete.Click
'Are You Sure
If MsgBox("Are You Sure", MsgBoxStyle.OKCancel, "Service Estimate: Warning") = MsgBoxResult.OK Then
'Declare ADODB Objects
Dim cnnDelete As New ADODB.Connection()
'Open ADODB Connection
cnnDelete.Open("Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Estimate\EstimatesDB.mdb;", _
"Admin", "")
'Declare RecordSet
Dim rstDelete As New ADODB.Recordset()
'Query
Dim StrDelete As String = "Select * from Users Where UserID = " & txtUserID.Text & ""
'Fill RecordSet
With rstDelete
.ActiveConnection = cnnDelete
.Open(StrDelete, , _
ADODB.CursorTypeEnum.adOpenKeyset, _
ADODB.LockTypeEnum.adLockOptimistic)
End With
'Update RecordSet
rstDelete.Delete()
'Close Connection
cnnDelete.Close()
'MsgBox
MsgBox("The User Has Been Deleted", , "Service Estimate")
'Refresh LstUsers
PopulateLstUsers()
Else
'MsgBox Not Deleted
MsgBox("User '" & txtEditUserName.Text & "', Not Deleted", , "Service Estimate")
End If
End Sub
I hope that code is readable.
Any suggestions?
Thanks!
[edit]it's more readable with
Visual Basic:
tags[/edit]
Last edited by a moderator: