Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void UpdateEmploee(Employee employee)
- {
- using (var conn = new SqlConnection(connStr))
- {
- const string commandStr = @"
- UPDATE [dbo].[Сотрудники]
- SET [Фамилия] = @lastName,
- [Код_отдела] = @kodOtd,
- [Имя] = @name,
- [Отчество] = @patronymic,
- [Должность] = @position,
- [Дата_рождения] = @birthday,
- [Дата_приема_на_работу] = @dayOfEmployment
- WHERE [Код_сотрудника] = @employeeId";
- DbCommand command = conn.CreateCommand();
- command.CommandText = commandStr;
- command.CommandType = CommandType.Text;
- command.Parameters.Add(new SqlParameter
- {
- ParameterName = "@lastName",
- SqlDbType = SqlDbType.NVarChar,
- Size = 50,
- Value = employee.LastName
- });
- command.Parameters.Add(new SqlParameter
- {
- ParameterName = "@name",
- SqlDbType = SqlDbType.NVarChar,
- Size = 20,
- Value = employee.Name
- });
- command.Parameters.Add(new SqlParameter
- {
- ParameterName = "@patronymic",
- SqlDbType = SqlDbType.NVarChar,
- Size = 50,
- Value = employee.Patronymik
- });
- command.Parameters.Add(new SqlParameter
- {
- ParameterName = "@position",
- SqlDbType = SqlDbType.NVarChar,
- Size = 50,
- Value = employee.Position
- });
- command.Parameters.Add(new SqlParameter
- {
- ParameterName = "@birthday",
- SqlDbType = SqlDbType.Date,
- Value = employee.Brthday
- });
- command.Parameters.Add(new SqlParameter
- {
- ParameterName = "@dayOfEmployment",
- SqlDbType = SqlDbType.Date,
- Value = employee.DayOfEmployment
- });
- command.Parameters.Add(new SqlParameter
- {
- ParameterName = "@kodOtd",
- SqlDbType = SqlDbType.Int,
- Value = employee.KodOtdela
- });
- command.Parameters.Add(new SqlParameter
- {
- ParameterName = "@employeeId",
- SqlDbType = SqlDbType.Int,
- Value = employee.KodOtdela
- });
- conn.Open();
- command.ExecuteNonQuery();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement