Get total rows from database

Get total rows from database through stored procedure and business lay

Page 1 of 1

1 Replies - 2162 Views - Last Post: 01 September 2009 - 04:59 AM Rate Topic: -----

#1 s20610639   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 35
  • Joined: 21-April 09

Get total rows from database

Post icon  Posted 01 September 2009 - 04:35 AM

Hey guys i need to get the total rows in a SQL database table i have created the stored procedure already. this method is suppose to use that stored procedure and return the number of rows. Can anyone help.
public int GetTotalGames()
		{
			SqlConnection con = new SqlConnection(ConnectionString);
			SqlCommand cmdGetTotalGames = new SqlCommand("procGetTotalGames", con);
			cmdGetTotalGames.CommandType = CommandType.StoredProcedure;

			try
			{
				con.Open(); 

dont know how to go forward

Is This A Good Question/Topic? 0
  • +

Replies To: Get total rows from database

#2 eclipsed4utoo   User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1536
  • View blog
  • Posts: 5,972
  • Joined: 21-March 08

Re: Get total rows from database

Posted 01 September 2009 - 04:59 AM

public int GetTotalGames()
{
      int number = 0;

      using (SqlConnection con = new SqlConnection())
      {
             using (SqlCommand cmd = new SqlCommand("", con))
             {
                     cmd.CommandType = CommandType.StoredProcedure;

                     con.Open();

                     number = (int)cmd.ExecuteScalar();
             }
      }

      return number
}


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1