DbAgentObj db = new DbAgentObj(); string sql = "SELECT COUNT(*) FROM Customers"; int numCustomers = (int)db.ExecuteScalar(sql); Console.WriteLine("There are {0} customers in the database.", numCustomers);
DbAgentObj db = new DbAgentObj(); string sql = "SELECT AVG(Salary) FROM Employees WHERE DepartmentID = @DeptID"; SqlParameter param = new SqlParameter("@DeptID", SqlDbType.Int); param.Value = 2; decimal avgSalary = (decimal)db.ExecuteScalar(sql, param); Console.WriteLine("The average salary for the department is {0:C}.", avgSalary);These examples use the DbAgentObj class, which is part of a package library that is not specified in the given information. It is likely that the DbAgentObj class is part of a custom library created by the user.