Please support our VB.NET advertiser: Programming Forums
Views: 3541 | Replies: 12
![]() |
Your First question,
I'll explain you what this code does.
In the database,if there is only one value to be populated you can use something like this
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,
CompanyA
CompanyB
CompanyC
CompanyD
All the four Company values will be store into the DataReader.
Then if you use this code,
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,
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,
Your answer is YES.
Since I declared Vcounty as a String,
I needed to convert values in the dreader to String.
I hope that helps.
•
•
•
•
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 WhileWhat 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
•
•
Join Date: Jun 2005
Posts: 17
Reputation:
Rep Power: 4
Solved Threads: 0
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...
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...
•
•
•
•
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
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)





Linear Mode