Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void Main()
- {
- //SqlConnection dbCon = new SqlConnection("Server=.\\MSSQL; " +
- // "Database=TelerikAcademy; Integrated Security=true");
- SqlConnection dbCon = new SqlConnection("Data Source=localhost; Integrated Security=SSPI;" +
- "Initial Catalog=TelerikAcademy");
- dbCon.Open();
- using (dbCon)
- {
- SqlCommand cmdCount = new SqlCommand(
- "SELECT COUNT(*) FROM Employees", dbCon);
- int employeesCount = (int)cmdCount.ExecuteScalar();
- Console.WriteLine("Employees count: {0} ", employeesCount);
- Console.WriteLine();
- Console.WriteLine("The most senior 10 employees:");
- SqlCommand cmdAllEmployees = new SqlCommand(
- "SELECT TOP 10 * FROM Employees ORDER BY HireDate", dbCon);
- SqlDataReader reader = cmdAllEmployees.ExecuteReader();
- using (reader)
- {
- while (reader.Read())
- {
- string firstName = (string)reader["FirstName"];
- string lastName = (string)reader["LastName"];
- decimal salary = (decimal)reader["Salary"];
- Console.WriteLine("{0} {1} - {2}", firstName, lastName, salary);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment