retrieving data in a list box control

srivalli

Well-known member
Joined
May 4, 2005
Messages
189
Programming Experience
Beginner
In my form i have one field bankname

now i am adding some banks (say 5) to the backend.

it is being updated.

i kept one button which shows the names of all the banks.(in a listbox cntrl)

after data is displayed in the listbox ,i added one more bank.

data is updated in the database.

but while clicking the button,in listbox instead of showing 6 banks the data is

displayed twice that is in listbox i am getting 11 banks.

so i want to refresh the details every time when i click the button.

hope my query is clear
thank u
 

angitapalli

Member
Joined
Mar 29, 2005
Messages
7
Programming Experience
1-3
Hi,

First clear the lisbox cotrol and then requery the database. If you dont clear, the items will be added to the existing items.

listboxname.items.clear()

Hope this works out.
 

JuggaloBrotha

VB.NET Forum Moderator
Staff member
Joined
Jun 3, 2004
Messages
4,524
Location
Lansing, MI; USA
Programming Experience
10+
here's another perspective on the items listed in the listbox

if the items in the listbox come straight from the database (ie it's bound to a dataset) then when you add a bank to the list (add it to the dataset then update the DB from the dataset)

then all you need to do is refresh the dataset by clearing it:
dsDataSet.Clear()
daDataAdapter.Fill(dsDataSet)

and that will refresh the listbox as well (since it's bound to the dataset that gets cleared then refilled)

hope that helps, if you would like more info on using bound controls to datasets feel free to ask myself, kulrom, jmcilhinney, paszt
 

srivalli

Well-known member
Joined
May 4, 2005
Messages
189
Programming Experience
Beginner
i got it thksss

i tried using ds.clear method
and igot it.
thank u


JuggaloBrotha said:
here's another perspective on the items listed in the listbox

if the items in the listbox come straight from the database (ie it's bound to a dataset) then when you add a bank to the list (add it to the dataset then update the DB from the dataset)

then all you need to do is refresh the dataset by clearing it:
dsDataSet.Clear()
daDataAdapter.Fill(dsDataSet)

and that will refresh the listbox as well (since it's bound to the dataset that gets cleared then refilled)

hope that helps, if you would like more info on using bound controls to datasets feel free to ask myself, kulrom, jmcilhinney, paszt
 
Top Bottom