Setting label = datasource...

R

Roy

Could someone please post some sample code on how to set an <asp:label>
equal to the results of a sql query?

This seems like it should be simple, but I can't seem to get it done.
 
G

Guest

Well what do you get as a return? a SqlDataReader, DataView?
to get every row into the table you'll have to loop around, otherwise, use a
DataGrid to display row by row:

while(pData.Read())
Label.Text += pData.GetString(0);

Hope you getting string!

Al
 
G

Guest

y,

If you are going to have only one value in your result of a sqlquery thenyou
can use the following code to bind that single value to a label box.

Store that single value in a variable,say "MyVariable" for example, and
assign it to label cotrol as follows.

<asp:Label id="Label1" Text ='<%# MyVariable %>' runat=server/>

You've to write the following line in one of your event's let us Page_Load
event

Page.DataBind();


cheers,

Jerome. M
 
R

Roy

Thanks for the input guys.

Basically, I'm trying to set a label equal to a specific row in a
table. The row would have about 6 columns in it, but it would always be
just a single row. By the same token, I'd like it to look good... Can I
set it equal to a specific field? IOW, break up the row into it's
constituent parts?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top