Gurjeet Singh

Gurjeet Singh

  • 2.1k
  • 90
  • 92.2k

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)
  return result;

  static Class5()
  Con_String = WebConfigurationManager.ConnectionStrings["Example"].ConnectionString;



CREATE PROCEDURE dbo.StoredProcedure1
RETURN (select count(*) from HR)

Answers (1)