473,386 Members | 1,830 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Populate Listbox from a database

Folks,

I have read all the posts about databases I could find and I think I
need a little more help. I want to take all the items from a field in
an access database and use them as list items in a list box. Let's say
the listbox is called listAddress, the database is address.mdb, the
table is tblName and the field is fieldName.

Could someone give me code to populate the listbox? I only need it
populated once, I don't need to update it and don't want to update the
database.

I really appreciate any help,

Joe

Aug 2 '06 #1
4 11108
Joe,

First, you will need to create an OleDbDataAdapter with the query to get
the contents of the field from the table. This will populate the dataset
with a table that has a client-side representation of the data.

Then, you can set the DataSource property of the ListBox class to the
DataTable (or data set, with the name of the DataTable being set for the
DataMember property).

Once you do that, you need to set the DisplayMember property to the name
of the field on the data table which you want displayed in your listbox.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Joe Blow" <bl*****@hotmail.comwrote in message
news:11*********************@i3g2000cwc.googlegrou ps.com...
Folks,

I have read all the posts about databases I could find and I think I
need a little more help. I want to take all the items from a field in
an access database and use them as list items in a list box. Let's say
the listbox is called listAddress, the database is address.mdb, the
table is tblName and the field is fieldName.

Could someone give me code to populate the listbox? I only need it
populated once, I don't need to update it and don't want to update the
database.

I really appreciate any help,

Joe

Aug 2 '06 #2

Nicholas Paldino [.NET/C# MVP] wrote:
Joe,

First, you will need to create an OleDbDataAdapter with the query to get
the contents of the field from the table. This will populate the dataset
with a table that has a client-side representation of the data.

Then, you can set the DataSource property of the ListBox class to the
DataTable (or data set, with the name of the DataTable being set for the
DataMember property).

Once you do that, you need to set the DisplayMember property to the name
of the field on the data table which you want displayed in your listbox.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
Thanks but I need a bit more help. I setup the adapter as you
described with the query. Now how do I setup a dataset to get that
information?

I have to do that before I can set the DataSource property of the
listbox, right?

Joe

Aug 2 '06 #3
Joe,

You need to call the Fill method on the DataAdapter, passing a dataset
to be filled.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Joe Blow" <bl*****@hotmail.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
>
Nicholas Paldino [.NET/C# MVP] wrote:
>Joe,

First, you will need to create an OleDbDataAdapter with the query to
get
the contents of the field from the table. This will populate the dataset
with a table that has a client-side representation of the data.

Then, you can set the DataSource property of the ListBox class to the
DataTable (or data set, with the name of the DataTable being set for the
DataMember property).

Once you do that, you need to set the DisplayMember property to the
name
of the field on the data table which you want displayed in your listbox.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

Thanks but I need a bit more help. I setup the adapter as you
described with the query. Now how do I setup a dataset to get that
information?

I have to do that before I can set the DataSource property of the
listbox, right?

Joe

Aug 2 '06 #4
Thanks,

Worked like a champ.

Joe

Aug 6 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: James Goodman | last post by:
I have a listbox named sub1 on an asp page. I need to fill this list with values from a table. These are selected based upon the selection of a value/s in another listbox. It was suggested that I...
2
by: Wishing I was skiing mom | last post by:
Newbie to VB .NET. My solution contains an item maintenance screen, one of the fields on the screen is an item status, this field is defined as a listbox. The listbox item property contains a...
5
by: Mark | last post by:
How can I populate a listbox with a list of the filenames in a certain folder? Can a query retrieve the filenames from a folder? Thanks! Mark
1
by: Grant Hammond | last post by:
I have a callback function that populates a listbox with a list of file names in a folder. This code came from Terry Kreft/Dev Ashish some years ago. I now want to add another column to the list...
1
by: Mike | last post by:
How can i populate a list box from a text file? I create a list of files within a text file and I want to populate the list box with that list to allow the users to select the web server to test...
3
by: Robert W. | last post by:
I have a SQL Server table called "ClosedMonths" that contains two pertinent fields: Yearx Monthx 2000 1 2000 2 2000 3 I want to simply query this...
1
by: edwordsigh | last post by:
Hello All! I would like to know where I can get started on a problem I've been having. I am currently trying to populate a listbox in visual basic from an access database file. Specifically, I am...
4
by: rn5a | last post by:
I have a ListBox which should list all the files & directories that exist in a particular directory. The problem is I can get the ListBox to list either all the files or all the directories but not...
1
by: Chaihana Joe | last post by:
Hi I'm trying to populate a listbox as a value list in code (access 2003). Unfortunately I'm getting 'runtime error 2176 - the setting for this property is too long' somewhere around the 2000...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.