Guest User

Untitled

a guest
Aug 19th, 2019
337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. using SoftUni.Data;
  2. using SoftUni.Data.Models;
  3. using System;
  4. using System.Data.SqlClient;
  5.  
  6. namespace SoftUni
  7. {
  8.  
  9. public class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. SoftUniContext context = new SoftUniContext();
  14. Console.WriteLine(GetEmployeesFullInformation(context));
  15. }
  16. public static string GetEmployeesFullInformation(SoftUniContext context)
  17. {
  18. string res = string.Empty;
  19.  
  20. string connString = "Server=SVILEN-PC\\SQLEXPRESS;Database=SoftUni;Integrated Security=True;";
  21. using (SqlConnection connection = new SqlConnection(connString))
  22. {
  23. connection.Open();
  24. SqlCommand command = new SqlCommand("SELECT * FROM Employees ORDER BY EmployeeId", connection);
  25. SqlDataReader reader = command.ExecuteReader();
  26.  
  27. using (reader)
  28. {
  29. while (reader.Read())
  30. {
  31. Employee emp = new Employee();
  32. emp.FirstName = reader["FirstName"]?.ToString();
  33. emp.MiddleName = reader["MiddleName"]?.ToString();
  34. emp.LastName = reader["LastName"]?.ToString();
  35. emp.JobTitle = reader["jobTitle"]?.ToString();
  36. emp.Salary = (decimal)reader["Salary"];
  37. res+=$"{emp.FirstName} {emp.MiddleName} {emp.LastName} {emp.JobTitle} {emp.Salary:f2}" +"\n";
  38.  
  39. }
  40. }
  41. return res.TrimEnd();
  42. }
  43. }
  44.  
  45.  
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment