RSS Forums RSS
Please support our VB.NET advertiser: Programming Forums
Views: 3541 | Replies: 12
Reply
Join Date: Feb 2005
Posts: 175
Reputation: Letscode is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 5
Letscode's Avatar
Letscode Letscode is offline Offline
Junior Poster

Re: Drop Downlist Not Loading

  #11  
Aug 7th, 2005
Your First question,

In your code when you write ----> While dreader.Read()
ddlCompanyName.Items.Add(New ListItem(dreader(0).ToString()))
End While <-------------



I'll explain you what this code does.

While dreader.Read()
                ddlCompanyName.Items.Add(New ListItem(dreader(0).ToString()))
            End While


In the database,if there is only one value to be populated you can use something like this

ddlCompanyName.Items.Add(New ListItem(dreader(0).ToString()))


But in our database there are more than one value to be populated inside the DropDownlist,

For example say,

CompanyA
CompanyB
CompanyC
CompanyD

Say you wanna populate these four values into the database,
your first step will be to use a DataReader to store these four values into the database.

Once you execute this code,

dreader = cmdcounty.ExecuteReader()


CompanyA
CompanyB
CompanyC
CompanyD

All the four Company values will be store into the DataReader.



Then if you use this code,

ddlCompanyName.Items.Add(New ListItem(dreader(0).ToString()))


Only the value CompanyA will be populated into the DropDownlist.

But you need the four values to be populated into the DropDownlist.

So you write somekind of a loop,

While dreader.Read()
                ddlCompanyName.Items.Add(New ListItem(dreader(0).ToString()))
            End While


What this code does is that it reads the DataReader,
1.checks whether Datareader has any values.

2.If there are any values then the second line in the code will be executed,

ddlCompanyName.Items.Add(New ListItem(dreader(0).ToString()))

This code creates a NEW ITEMLIST and then populates the value from the dataReader into the DropDownlist,

3.Since its a while loop it goes back to Step 1 and grabs the second item in the Datareader and goes to step 2 . This continues until Datareader fails to read any more items in its list.

Now the Dropdownlist has All the four Company values,

CompanyA
CompanyB
CompanyC
CompanyD


I hope that answers your first question.

Now regarding you second question,

are you doing the .ToString so that the value of the string can be used in the ---> Vcounty = ddlCompanyName.SelectedItem.Text <------- in the ddlCustomers_SelectedIndexChanged event ??????


Your answer is YES.

Since I declared Vcounty as a String,

Dim Vcounty As String


I needed to convert values in the dreader to String.

I hope that helps.
Save White Tiger
Reply With Quote  
Join Date: Jun 2005
Posts: 17
Reputation: erikkl2000 is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
erikkl2000 erikkl2000 is offline Offline
Newbie Poster

Re: Drop Downlist Not Loading

  #12  
Aug 10th, 2005
Thank you for helping me with this! :cheesy:

I seem late to respond that it because i try to let as much soak in as i can.. This to string is really bothering me... I have paper taped up on my walls with different defenitions and it still is not completely soaking in.. My main concern here is that i know when hte .Tostring is used,, it enables a representation of the current object to be accessed,, HERE is the question... Where is it held until it is used??? .Tostring,, (to where???) at run time does the string go directly to the object that will utilize its value?,.,

I know these are small patatos; however, i am in need to get a better understanding about this..

I am missing something some where..

Erik...
Reply With Quote  
Join Date: Feb 2005
Posts: 175
Reputation: Letscode is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 5
Letscode's Avatar
Letscode Letscode is offline Offline
Junior Poster

Re: Drop Downlist Not Loading

  #13  
Aug 18th, 2005
Originally Posted by erikkl2000
Thank you for helping me with this! :cheesy:

I seem late to respond that it because i try to let as much soak in as i can.. This to string is really bothering me... I have paper taped up on my walls with different defenitions and it still is not completely soaking in.. My main concern here is that i know when hte .Tostring is used,, it enables a representation of the current object to be accessed,, HERE is the question... Where is it held until it is used??? .Tostring,, (to where???) at run time does the string go directly to the object that will utilize its value?,.,

I know these are small patatos; however, i am in need to get a better understanding about this..

I am missing something some where..

Erik...

Hmm.I'm not sure what you are asking.
The .Tostring is a property which converts the values in the DataReader to a string.

Thats It.Its just a property.Even if you remove the Tostring property your code will work.

Only thing to be noted is you'll have to keep track of dataType of the values which you are accessing in the DataReader if you remove the ToString Property.
Save White Tiger
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 9:40 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC