Listbox values not reflecting db updates

cfisher440

Well-known member
Joined
Oct 11, 2005
Messages
73
Programming Experience
1-3
I have a program that populates values in a listbox from values stored in a database. When I make a change in the database (to add or remove something from the list) it does not show the updated values in the listbox.
It's as if it is caching the values and keeping them there.
I have to recompile the project, copy it to the server, and restart IIS and then the listbox values reflect the updated database table.

Any ideas as to why this is happening?
 
repopulate?

Thanks for the response Kulrom,
By repopulate, you mean using the databind method of each listbox?
Because I am using the databind method. Shouldn't databinding repopulate the box with the values in the db?
Possibly you are talking about something different?

It's worth noting also that when I run the page from my PC which involves compiling it, it shows me the updated values in the listbox.
The same program I deployed on the server won't show the updated values.
 
Last edited:
Ok create a separated procedure which would populate the certain listbox and call as you need. I.e. you have Sub named BindListBox
VB.NET:
Private Sub BindListBox()
{...}
'fill the dataset throught the dataadapter object and then
[SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].ListBox1.DataSource = datasetobject.Tables(0)
[/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].ListBox1.DisplayMember = [/SIZE][SIZE=2][COLOR=#800000]"field2"
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].ListBox1.ValueMember = [/SIZE][SIZE=2][COLOR=#800000]"field1"[/COLOR][/SIZE]
End Sub
make the changes and then just call the procedure from the above.
Notice that if you are using selected index or value changed you should use add and remove handler methods.

HTH
Regards ;)
 
figured it out

Figured it out.
In my code when I went out to get the values I was referencing what was in the cache. My function was this

VB.NET:
[SIZE=2][COLOR=#0000ff]
Function[/COLOR][/SIZE][SIZE=2] GetResolutions() [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] DataSet
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] dsResolutions [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] DataSet
[/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] HttpContext.Current.Cache("dsResolutions") [/SIZE][SIZE=2][COLOR=#0000ff]Is[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Nothing[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] sSelect [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = "SELECT resID, labeltext, subIssueID " _
& "FROM resolution"
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] daResolutions [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] OleDb.OleDbDataAdapter(sSelect, Connection)
daResolutions.MissingSchemaAction = MissingSchemaAction.AddWithKey
daResolutions.FillSchema(dsResolutions, SchemaType.Mapped)
daResolutions.Fill(dsResolutions, "resolution")
HttpContext.Current.Cache("dsResolutions") = dsResolutions
[/SIZE][SIZE=2][COLOR=#0000ff]Else
[/COLOR][/SIZE][SIZE=2]dsResolutions = HttpContext.Current.Cache("dsResolutions")
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Return[/COLOR][/SIZE][SIZE=2] dsResolutions
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Function[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff][/COLOR][/SIZE]
''''''Got rid of the httpContext stuff'''''''''''
''''''So it looks like this''''''''''''''''''''''
VB.NET:
[SIZE=2][COLOR=#0000ff]
Function[/COLOR][/SIZE][SIZE=2] GetResolutions() [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] DataSet
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] dsResolutions [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] DataSet
[/SIZE][SIZE=2][COLOR=#008000]'If HttpContext.Current.Cache("dsResolutions") Is Nothing Then
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] sSelect [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = "SELECT resID, labeltext, subIssueID " _
& "FROM resolution"
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] daResolutions [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] OleDb.OleDbDataAdapter(sSelect, Connection)
daResolutions.MissingSchemaAction = MissingSchemaAction.AddWithKey
daResolutions.FillSchema(dsResolutions, SchemaType.Mapped)
daResolutions.Fill(dsResolutions, "resolution")
HttpContext.Current.Cache("dsResolutions") = dsResolutions
[/SIZE][SIZE=2][COLOR=#008000]'Else
[/COLOR][/SIZE][SIZE=2]dsResolutions = HttpContext.Current.Cache("dsResolutions")
[/SIZE][SIZE=2][COLOR=#008000]'End If
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Return[/COLOR][/SIZE][SIZE=2] dsResolutions
[/SIZE]

I read that this would basically make the application run faster (and it did), but it was also making it cache the dataset, thus when I updated the db, the listboxes were not recognizing the changes.
Sorry for not showing ya'll that before.

Thanks for the help Kulrom, I appreciate it.
 
Back
Top