Solved

Handling Textbox Event

Posted on 2007-11-28
4
367 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
  • 2
  • 2
4 Comments
 
LVL 6

Accepted Solution

by:
Roopesh_7 earned 500 total points
Comment Utility
Label1.Text = cmd.ExecuteScalar()
con.Close()
0
 

Author Comment

by:cybernation989
Comment Utility
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
Comment Utility
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
Comment Utility


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

Thanks
Roops
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

763 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now