What is the simplest way in C# (.cs file) to get the count from the SQL command
SELECT COUNT(*) FROM table_name
into an int
variable?
Use SqlCommand.ExecuteScalar() and cast it to an int
:
cmd.CommandText = "SELECT COUNT(*) FROM table_name";
Int32 count = (Int32) cmd.ExecuteScalar();