TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Gurjeet Singh
NA
90
94.5k
Count Rows
Aug 9 2011 6:51 AM
Hi i want to show total rows in my HR table on label. I have wrote below code in App_Code\Class5
which code should i used in Label.Text property.
using
System;
using
System.Collections.Generic;
using
System.Data;
using
System.Data.SqlClient;
using
System.Web.Configuration;
using
System.Data.SqlTypes;
public
class
Class5
{
private
static
readonly
string
Con_String;
public
int
result=0;
private
int
CountRows()
{
SqlConnection
con =
new
SqlConnection
(Con_String);
SqlCommand
cmd =
new
SqlCommand
(
"StoredProcedure1"
,con);
cmd.CommandType =
CommandType
.StoredProcedure;
cmd.Parameters.Add(
"@ReturnVal"
,
SqlDbType
.Int).Direction =
ParameterDirection
.ReturnValue;
using
(con)
{
con.Open();
cmd.ExecuteNonQuery();
result=(
int
)cmd.Parameters[
"@ReturnVal"
].Value;
}
return
result;
}
static
Class5()
{
Con_String =
WebConfigurationManager
.ConnectionStrings[
"Example"
].ConnectionString;
}
}
StoredProcedure
CREATE PROCEDURE dbo.StoredProcedure1
AS
RETURN (select count(*) from HR)
Reply
Answers (
1
)
How to display data in Table in ASP.NET
How to create role in ASP.NET