Assign values to 3 different labels...

eramgarden

Contributor
Joined
Mar 8, 2004
Messages
579
I have a sql that returns 3 rows..i want each row assigned to a different label:

This is what I have:

cmd.CommandText = "Select label from lmaster where label_group ='Generic' and s_id= " & "'" & Session("Mode") & "'"


cnn.Open()

Dim dr As SqlDataReader = cmd.ExecuteReader()

Do While dr.Read()

btnContact.Text = dr.GetString(0)

btnSite.Text = dr.GetString(0)

btnIncident.Text = dr.GetString(0)

Loop

The way I have it, it assigns the first row to ALL 3 lables, then assign the second row to ALL 3 lables, then assigns the 3rd row to ALL 3 lables..

an ideas on how to do this?
 
use a DataSet instead, and then do something like

Label1.Text = ds.Tables(0).Rows(0).Item(0)
Label2.Text = ds.Tables(0).Rows(1).Item(0)
Label3.Text = ds.Tables(0).Rows(2).Item(0)

just like your almost identical post on this.... DataReader is a bad choice for what you are wanting
 
you could also just use a datareader to make things a bit quicker.

datareader.read: Label1.Text = datareader(0)
datareader.read: Label2.Text = datareader(0)
datareader.read: Label3.Text = datareader(0)

just an alternative!!
 
Back
Top