Wrox Programmer Forums
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 4th, 2004, 12:48 AM
Authorized User
 
Join Date: Sep 2004
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default Count

i'm developing a web abased application in VB .NET. i created a count button which displays the number of records available in a table. the code is as below:

Dim sqlCount As String = "SELECT COUNT(code) from subarea"
        lblCount.Text = sqlCount & " records. "
        lblCount.Visible = True

i want the result of the sql to be dislayed in a lablel. How do i do that? what should i write instead of sqlCount in the below code:
lblCount.Text = sqlCount & " records. "

Thanks
 
Old September 5th, 2004, 02:42 AM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hello Sheikha,
you shouldnt do it in that way,
do these steps,
1-make a SelectCommand object
2-set it with your query and SELECT @@rowcount
3.use ExecuteScalar() method through your command object(for returning the rowcount)and convert it to String for assigning it to Text property ....
However if you are using DataView you could use it easier ...
HtH.

--------------------------------------------
Mehdi.:)
 
Old September 5th, 2004, 10:57 PM
Authorized User
 
Join Date: Sep 2004
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Mahdi:

Thanks for helping me out but i didnt really understand the steps. Could you kindly elaborate?
 
Old September 6th, 2004, 06:08 AM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

Have a look at this example ...
Code:
SqlConnection objConnection=new SqlConnection(strConnection);
//strSql is your select query
SqlCommand objCommand=new SqlCommand(strSql,objConnection);
objConnection.Open();
DataGrid1.DataSource=objCommand.ExecuteReader();
DataGrid1.DataBind();
objConnection.Close();
objCommand.CommandText="select @@rowcount";
objConnection.Open();
TextBox1.Text=objCommand.ExecuteScalar().ToString();
objConnection.Close();
(however you can work with Count property of DataView object but you should
consider that you work in disconnected environment
)
HtH.


--------------------------------------------
Mehdi.:)
 
Old September 16th, 2004, 07:39 PM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hello again sheikha!!!
dont use this method I told you
(you will face some problems if many users hit your site)
you should use a Stored Procedure with an Output Parameter
(see here for the cause of this problem)
if you face some problems in using Stored Procedures ask me.


--------------------------------------------
Mehdi.:)





Similar Threads
Thread Thread Starter Forum Replies Last Post
XSL: Count = Count + 1 elayaraja.s XSLT 3 July 18th, 2008 03:21 AM
is there any in built function to count page count g.tamilselvan MySQL 1 February 15th, 2006 07:43 AM
Need Count Help ~Bean~ SQL Language 11 August 9th, 2005 11:22 PM
Count, sum, count a value, return records CongoGrey Access 1 April 18th, 2005 02:25 PM
count() crmpicco MySQL 1 January 28th, 2005 01:44 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.