Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void AddEmployee(Employee employee)
- {
- using (var conn = new SqlConnection(connStr))
- {
- const string commandStr = @"
- INSERT INTO [dbo].[Сотрудники]
- ([Фамилия]
- ,[Имя]
- ,[Отчество]
- ,[Должность]
- ,[Дата_рождения]
- ,[Дата_приема_на_работу]
- ,[Код_отдела] )
- VALUES (@lastName, @name, @patronymic, @position, @birthday, @dayOfEmployment, @kodOtd)";
- 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
- });
- conn.Open();
- command.ExecuteNonQuery();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement