Solved

Handling Textbox Event

Posted on 2007-11-28
4
372 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 500 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
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, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

630 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