User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 374,171 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,446 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 447 | Replies: 2
Reply
Join Date: Mar 2008
Posts: 1
Reputation: cynxiann is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
cynxiann cynxiann is offline Offline
Newbie Poster

How to retrieve records from the database one at a time?

  #1  
Mar 24th, 2008
I would like to know how can I retrieve results/records from a database one at a time to make it appear in different labels..

eg.
row number 1 of the database's records = apple
lb_fruit.Text = apple

row number 2 of the database's records = pear
lb_fruit2.Text = pear

.
.

And so on..
There's loads of rows that I need to retrieve..
Is there anyway then better then writing loads of sql statements?
Thanks loads in advance. (:
AddThis Social Bookmark Button
Reply With Quote  
Join Date: May 2005
Posts: 494
Reputation: techniner is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 18
techniner techniner is offline Offline
Posting Pro in Training

Re: How to retrieve records from the database one at a time?

  #2  
Mar 25th, 2008
Yes, load them into an array and then for each on the array and display the entire array and build labels as needed.
Did my post help?
Visit Little Jon's Web Portal


Generate Traffic with Maximum Traffic Software
Reply With Quote  
Join Date: Sep 2007
Posts: 1,054
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 61
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: How to retrieve records from the database one at a time?

  #3  
Mar 28th, 2008
I would stay away from the array, as there is no need to use more resources since you are already using a datareader to read the data into an array. Your best bet is to put a repeater (depending on your situation and where these labels are placed), and binding it to the repeater.
  1. Dim dtrReader As SqlDataReader = cmdSelect.ExecuteReader()
  2.  
  3. If dtrReader.HasRows Then
  4. repeater1.DataSource = dtrReader
  5. repeater1.DataBind()
  6. End If
  7.  
  8.  
  9.  
  10. ------------
  11.  
  12. <asp:Repeater ID="repeater1" runat="server">
  13. <ItemTemplate>
  14. <asp:Label ID="lbl" Text='<%# Eval("fruitorColumnName") %>' runat="server" />
  15. <br />
  16. </ItemTemplate>
  17. </asp:Repeater>
This will spit out information in this manner:

Apple
Banana
Orange
Pear
Zucchini
I answer pm's.
I answer questions.
I answer quickly.
I answer.
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)

 

DaniWeb ASP.NET Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the ASP.NET Forum

All times are GMT -4. The time now is 4:22 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC