Advertisement
Guest User

Untitled

a guest
Dec 17th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. public static void AddEmployee(Employee employee)
  2. {
  3. using (var conn = new SqlConnection(connStr))
  4. {
  5. const string commandStr = @"
  6. INSERT INTO [dbo].[Сотрудники]
  7. ([Фамилия]
  8. ,[Имя]
  9. ,[Отчество]
  10. ,[Должность]
  11. ,[Дата_рождения]
  12. ,[Дата_приема_на_работу]
  13. ,[Код_отдела] )
  14. VALUES (@lastName, @name, @patronymic, @position, @birthday, @dayOfEmployment, @kodOtd)";
  15.  
  16. DbCommand command = conn.CreateCommand();
  17. command.CommandText = commandStr;
  18. command.CommandType = CommandType.Text;
  19. command.Parameters.Add(new SqlParameter
  20. {
  21. ParameterName = "@lastName",
  22. SqlDbType = SqlDbType.NVarChar,
  23. Size = 50,
  24. Value = employee.LastName
  25. });
  26. command.Parameters.Add(new SqlParameter
  27. {
  28. ParameterName = "@name",
  29. SqlDbType = SqlDbType.NVarChar,
  30. Size = 20,
  31. Value = employee.Name
  32. });
  33. command.Parameters.Add(new SqlParameter
  34. {
  35. ParameterName = "@patronymic",
  36. SqlDbType = SqlDbType.NVarChar,
  37. Size = 50,
  38. Value = employee.Patronymik
  39. });
  40. command.Parameters.Add(new SqlParameter
  41. {
  42. ParameterName = "@position",
  43. SqlDbType = SqlDbType.NVarChar,
  44. Size = 50,
  45. Value = employee.Position
  46. });
  47.  
  48. command.Parameters.Add(new SqlParameter
  49. {
  50. ParameterName = "@birthday",
  51. SqlDbType = SqlDbType.Date,
  52. Value = employee.Brthday
  53. });
  54.  
  55. command.Parameters.Add(new SqlParameter
  56. {
  57. ParameterName = "@dayOfEmployment",
  58. SqlDbType = SqlDbType.Date,
  59. Value = employee.DayOfEmployment
  60. });
  61. command.Parameters.Add(new SqlParameter
  62. {
  63. ParameterName = "@kodOtd",
  64. SqlDbType = SqlDbType.Int,
  65. Value = employee.KodOtdela
  66. });
  67.  
  68.  
  69. conn.Open();
  70.  
  71. command.ExecuteNonQuery();
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement