using System.Data.SqlClient; using System.Data; public int GetNumberOfCustomers(string connectionString) { using (var connection = new SqlConnection(connectionString)) { connection.Open(); var command = connection.CreateCommand(); command.CommandText = "SELECT COUNT(*) FROM Customers"; var result = command.ExecuteScalar(); return Convert.ToInt32(result); } }This example queries the "Customers" table and returns the number of rows using the SELECT COUNT(*) statement. The ExecuteScalar method is used to retrieve the single value returned by the query. Package library: System.Data.SqlClient.