PC Review


Reply
Thread Tools Rate Thread

DataReader,ArrayList, ListBox

 
 
=?Utf-8?B?ZGVubmlzdDY4NQ==?=
Guest
Posts: n/a
 
      2nd Jul 2005
I'm developing in vs 2005 beta2 now. I've been using a table adapter to
populate comboboxes. That's fine, because these are mostly lookup tables
with 10 to 30 rows. But then I came to Authors. I have hundreds of authors.

I started a thread in the vs 2005 forums looking for a more economical way.
It boiled down to the topic title, but nobody to find a way to do it.
ArrayLists have one dimension. I need two entries, one for display, the
other for value. There is no databinding itself for the comboboxes. I use a
tableadapter insertquery to add a row. As you know, in 2005 we avoid all
those parameter statements.

I've looked through my six vs studio 2003 books - framework corereference,
vb.net core reference, ado.net core reference and three others. I've queries
msdn backward and forward. The datareader examples are message boxes or
filling textboxes. Never an example showing a real use for them, like
filling the display and value members of a combobox or listbox.

Can anybody help me here?

dennist685
 
Reply With Quote
 
 
 
 
=?Utf-8?B?S2VycnkgTW9vcm1hbg==?=
Guest
Posts: n/a
 
      2nd Jul 2005
dennist685,

One option is to retrieve just the data you need into a datatable. Then bind
the datatable to a listbox, combobox, etc. Once the control is bound, the
datatable is no longer needed. For example:

Dim cn As New OleDb.OleDbConnection("Provider=SQLOLEDB;Initial
Catalog=CustomerDataSQL;User ID=xx;Password=abcde")
Dim cmd As New OleDb.OleDbCommand
Dim dAdapter As New OleDb.OleDbDataAdapter
Dim dTable As New DataTable

cmd.CommandText = "Select LastName + ', ' + FirstName As
CustomerName, ID From Customers Order By CustomerName"

cn.Open()
cmd.Connection = cn

dAdapter.SelectCommand = cmd
dAdapter.Fill(dTable)

cn.Close()

lstCustomers.DisplayMember = "CustomerName"
lstCustomers.ValueMember = "ID"
lstCustomers.DataSource = dTable

The dTable data table was just a temporary variable, used to fill the control.

Now when the user selects a name from the combobox, the ID can be retrieved
from the combobox and used as a primary key to get just the record you are
interested in.

Kerry Moorman


"dennist685" wrote:

> I'm developing in vs 2005 beta2 now. I've been using a table adapter to
> populate comboboxes. That's fine, because these are mostly lookup tables
> with 10 to 30 rows. But then I came to Authors. I have hundreds of authors.
>
> I started a thread in the vs 2005 forums looking for a more economical way.
> It boiled down to the topic title, but nobody to find a way to do it.
> ArrayLists have one dimension. I need two entries, one for display, the
> other for value. There is no databinding itself for the comboboxes. I use a
> tableadapter insertquery to add a row. As you know, in 2005 we avoid all
> those parameter statements.
>
> I've looked through my six vs studio 2003 books - framework corereference,
> vb.net core reference, ado.net core reference and three others. I've queries
> msdn backward and forward. The datareader examples are message boxes or
> filling textboxes. Never an example showing a real use for them, like
> filling the display and value members of a combobox or listbox.
>
> Can anybody help me here?
>
> dennist685

 
Reply With Quote
 
bhawin13@indiatimes.com
Guest
Posts: n/a
 
      5th Jul 2005
Hello dennist685

visit http://aspnet.4guysfromrolla.com
You will find examples

regards,
bhawin13

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ArrayList and ListBox Bill Gower Microsoft Dot NET Framework Forms 3 3rd Apr 2007 07:05 PM
listbox bound to arraylist no changing values when values in arraylist are added or deleted Dave Microsoft VB .NET 0 11th Jan 2005 02:48 PM
ListBox, DataReader, ID and Description Guy Dillen Microsoft Dot NET Framework Forms 3 4th Dec 2004 01:35 PM
DataReader to ArrayList A.M Microsoft ADO .NET 4 11th May 2004 09:14 PM
DataReader and ListBox eAndy Microsoft Dot NET Framework Forms 5 24th Nov 2003 07:55 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:51 AM.