---
title: "How to get number of rows in a table in mysql"  
description: "How to get number of rows in a table in mysql"  
author: "Anonymous User"  
published: 2013-10-05  
updated: 2013-10-05  
canonical: https://www.mindstick.com/forum/1609/how-to-get-number-of-rows-in-a-table-in-mysql  
category: "c#"  
tags: ["c#"]  
reading_time: 2 minutes  

---

# How to get number of rows in a table in mysql

After a sleepless night and run over the StackOverflow I could not find the [method](https://www.mindstick.com/forum/166/webservice-method) ([function](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server)) that can resolve my problem.

What I wrote is very harder for the server. Is there any more clever way to [resolve this problem](https://answers.mindstick.com/qa/94690/why-does-it-take-google-chrome-so-long-to-open-in-my-computer-what-should-i-do-now-to-resolve-this-problem)?

**Here my [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii):**

```
public static int GetIndexLong(string TblName)
{
    int rowsNbr = 0;
    using(MySqlConnection conn = new MySqlConnection(PublicVariables.cs))
    {
        using(MySqlCommand cmd = new MySqlCommand("SELECT * FROM " + TblName, conn))
        {
            conn.Open();
            using (MySqlDataReader reader = cmd.ExecuteReader())
            {
                while (reader.Read())
                {
                    ++rowsNbr;
                }
            }
            return rowsNbr;
        }
    }
}
```

\

It does the [job](https://www.mindstick.com/articles/167406/how-to-upgrade-your-freelance-designer-job) but I know it's not the good way.

Working with C# [Express](https://www.mindstick.com/forum/156025/how-to-use-garmin-express-software) 2008 on .NET 4.0.

## Replies

### Reply by Anonymous User

Are you looking for count:

SELECT COUNT(*) FROM TableName


---

Original Source: https://www.mindstick.com/forum/1609/how-to-get-number-of-rows-in-a-table-in-mysql

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
