Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using SoftUni.Data;
- using SoftUni.Data.Models;
- using System;
- using System.Data.SqlClient;
- namespace SoftUni
- {
- public class Program
- {
- static void Main(string[] args)
- {
- SoftUniContext context = new SoftUniContext();
- Console.WriteLine(GetEmployeesFullInformation(context));
- }
- public static string GetEmployeesFullInformation(SoftUniContext context)
- {
- string res = string.Empty;
- string connString = "Server=SVILEN-PC\\SQLEXPRESS;Database=SoftUni;Integrated Security=True;";
- using (SqlConnection connection = new SqlConnection(connString))
- {
- connection.Open();
- SqlCommand command = new SqlCommand("SELECT * FROM Employees ORDER BY EmployeeId", connection);
- SqlDataReader reader = command.ExecuteReader();
- using (reader)
- {
- while (reader.Read())
- {
- Employee emp = new Employee();
- emp.FirstName = reader["FirstName"]?.ToString();
- emp.MiddleName = reader["MiddleName"]?.ToString();
- emp.LastName = reader["LastName"]?.ToString();
- emp.JobTitle = reader["jobTitle"]?.ToString();
- emp.Salary = (decimal)reader["Salary"];
- res+=$"{emp.FirstName} {emp.MiddleName} {emp.LastName} {emp.JobTitle} {emp.Salary:f2}" +"\n";
- }
- }
- return res.TrimEnd();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment