473,397 Members | 2,116 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Displaying a datasource field with a label

I am an absolute beginner and finding myself confused at every step that I
take in the learning process. It will get better.

Anyway, I have a SqlDataSource control on a form and at page load time I
want to display the contents of a field from the record set using a label
control.

I cannot for th elife of me figure out how to reference that field.

The datasource select command simply reads the count(*) of records in the
table via:

SELECT Count(*) As RcdCnt

What I want to do is simply assign that value to Label1.Text but lack of
familiarity with ASP.NET has stopped me cold. I expected to be able to say
something like:

Label1.Text = SqlDataSource1("RcdCnt")

Nope.

I know that there are all levels of knowledge and experience on this news
feed and sincerly hope that a rank beginner's question like this is welcome.
Dec 1 '07 #1
3 4252
What I want to do is simply assign that value to Label1.Text but lack of
familiarity with ASP.NET has stopped me cold. I expected to be able to say
something like:

Label1.Text = SqlDataSource1("RcdCnt")
Hi,

try this way

using (SqlConnection conn = new
SqlConnection(connectionString))
{
conn.Open();

string query = "select COUNT(*) from TABLE_NAME";

SqlDataAdapter da = new SqlDataAdapter(query, conn);

DataTable dt = new DataTable();

da.Fill(dt);

Label1.Text = dt.Rows[0].ToString();
}

I hope that will helps You.

BTW, check this site: http://asp.net/learn/
For me, it is great site for the peoples who starts learning asp.net.
Dec 1 '07 #2
Howdy,

Many ways of doing the task at hand, one possible:

string connectionString = "server=serv;database=db;uid=userId;pwd=passw" ;
int count = 0;

using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand command = new SqlCommand(
"SELECT Count(*) As RcdCnt FROM whatever", connection);
count = (int) command.ExecuteScalar();
}

label1.Text = count.ToString();

Hope it helps
--
Milosz
"James R. Davis" wrote:
I am an absolute beginner and finding myself confused at every step that I
take in the learning process. It will get better.

Anyway, I have a SqlDataSource control on a form and at page load time I
want to display the contents of a field from the record set using a label
control.

I cannot for th elife of me figure out how to reference that field.

The datasource select command simply reads the count(*) of records in the
table via:

SELECT Count(*) As RcdCnt

What I want to do is simply assign that value to Label1.Text but lack of
familiarity with ASP.NET has stopped me cold. I expected to be able to say
something like:

Label1.Text = SqlDataSource1("RcdCnt")

Nope.

I know that there are all levels of knowledge and experience on this news
feed and sincerly hope that a rank beginner's question like this is welcome.
Dec 2 '07 #3
Once again, Miloz, thank you!

I used the ExecuteScalar method without any trouble at all. In fact, that
was the last piece of the puzzel for my current page. Now off to the next
one!

It's the bits and pieces of practical, everyday, useful information that
aggregates into a 'tool bag' full of capabilities and you have added some
fine ones to mine.

Jim

"Milosz Skalecki [MCAD]" <mi*****@DONTLIKESPAMwp.plwrote in message
news:96**********************************@microsof t.com...
Howdy,

Many ways of doing the task at hand, one possible:

string connectionString = "server=serv;database=db;uid=userId;pwd=passw" ;
int count = 0;

using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand command = new SqlCommand(
"SELECT Count(*) As RcdCnt FROM whatever", connection);
count = (int) command.ExecuteScalar();
}

label1.Text = count.ToString();

Hope it helps
--
Milosz

Dec 2 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: euang | last post by:
Hi, I have been using access 2000 for two years on WINDOWS NT to display dynamic aweb page using ASP My ISP has now changed to Windows 2003, and I am having major problems displaying...
2
by: aabid | last post by:
I started using VWD 2.0 Express Edition. I am new to web applications. Can somebody post a sample code to show how to retrieve data from an SQL 2005 table and display in a textbox or label?. I am...
4
by: Luqman | last post by:
How can I display any field value in textbox of sqldatasource using VS.Net 2005 ? Say : Dim x as new AccessDataSource X.connectionstring="Data source="D:\mydb.mdb" X.Selectcommand="Select...
0
by: Luqman | last post by:
How can I display any field value in textbox of sqldatasource using VS.Net 2005 ? Say : Dim x as new AccessDataSource X.connectionstring="Data source="D:\mydb.mdb" X.Selectcommand="Select...
3
by: veaux | last post by:
I have a table that looks like below: Name, Address, Favorite Pet Bill Smith, 123 Smith St, Dogs Bill Smith, 123 Smith St, Cats The "Dogs" and "Cats" are actually in a lookup table, but have...
1
by: rodchar | last post by:
hey all, i have a label inside an item template of a datalist control. the datasource field type is money. well, when i databind the money field to the label.text it show a precision of 4....
7
by: Chuck Anderson | last post by:
I'm pretty much a JavaScript novice. I'm good at learning by example and changing those examples to suit my needs. That said .... ..... I have some select fields in a form I created for a...
1
by: cyningeston | last post by:
OS: WinXP Pro, VB/ASP/ADO.NET I'm building a web-based supplier management application. For each supplier we are required by the FDA to track certain documents. I've managed to pull them from...
3
by: blakerrr | last post by:
Hi everyone, I thought this would be easy, but I can't figure it out. I have a form that I want to view in datasheet view. The labels for my fields need to be a few words long, but the actual...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.