0

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. (:

3
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by SheSaidImaPregy
0

Yes, load them into an array and then for each on the array and display the entire array and build labels as needed.

0

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.

Dim dtrReader As SqlDataReader = cmdSelect.ExecuteReader()

If dtrReader.HasRows Then
  repeater1.DataSource = dtrReader
  repeater1.DataBind()
End If



------------

<asp:Repeater ID="repeater1" runat="server">
<ItemTemplate>
  <asp:Label ID="lbl" Text='<%# Eval("fruitorColumnName") %>' runat="server" />
  <br />
</ItemTemplate>
</asp:Repeater>

This will spit out information in this manner:

Apple
Banana
Orange
Pear
Zucchini

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.