How to get number of rows in a table in mysql

Total Post:28

 1570  View(s)
Rate this:

After a sleepless night and run over the StackOverflow I could not find the method (function) that can resolve my problem.

What I wrote is very harder for the server. Is there any more clever way to resolve this problem?

Here my code:

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))
            using (MySqlDataReader reader = cmd.ExecuteReader())
                while (reader.Read())
            return rowsNbr;

It does the job but I know it's not the good way.

Working with C# Express 2008 on .NET 4.0.

  1. Post:30

    Re: How to get number of rows in a table in mysql

    Are you looking for count:

    SELECT COUNT(*) FROM TableName

      Modified On Mar-31-2018 05:44:02 AM


Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.