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?
int
Use SqlCommand.ExecuteScalar() and cast it to an int:
cmd.CommandText = "SELECT COUNT(*) FROM table_name"; Int32 count = (Int32) cmd.ExecuteScalar();
1.4m articles
1.4m replys
5 comments
57.0k users