Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Handling Textbox Event

Posted on 2007-11-28
4
Medium Priority
?
373 Views
Last Modified: 2007-12-04
This is not an exam or Homework

You have written the following code segment for a Web form:

Dim con As New SqlConnection(conString)
con.Open()
Dim cmd As New SqlCommand("SELECT Count(*) As AuthorsCount FROM Authors", con)

You are supposed to display the number of authors in a Label control (Label1). Which of the following code snippets will achieve the stated goal?

1.
Label1.Text = cmd.ExecuteScalar()
con.Close()
 
2.
Label1.Text = cmd.ExecuteSQL()
con.Close()
 
3.
Label1.Text = cmd.ExecuteNonQuery()
con.Close()
 
4.
Label1.Text = cmd.ExecuteReader().Item("AuthorsCount")
con.Close()
0
Comment
Question by:cybernation989
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 6

Accepted Solution

by:
Roopesh_7 earned 2000 total points
ID: 20368087
Label1.Text = cmd.ExecuteScalar()
con.Close()
0
 

Author Comment

by:cybernation989
ID: 20380244
Thanks Roopesh!

But after reading a number of sites I think number 1 would just show the first row...

ExecuteScalar - Executes the query, and returns the first column of the first row in the result set returned by the query. Additional columns or rows are ignored.

so are you sure it will display the number of authors in a Label control (Label1)?
0
 

Author Comment

by:cybernation989
ID: 20380292
Guess I was wrong...

it shows how you can count the rows with executescalar at
http://forums.asp.net/p/1142892/1847306.aspx

so I guess you were right... still a little confused on how it works
0
 
LVL 6

Expert Comment

by:Roopesh_7
ID: 20382416


Hey friend,
Try this with an exaple so you will find:)

Thanks
Roops
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question