Example #1
0
        /// <summary>
        /// Добавление записи в таблицу.
        /// </summary>
        /// <param name="task">Добавляемое задание.</param>
        /// <returns>Id добавленной записи.</returns>
        private int AddRecordToTable(Task task)
        {
            string query = "INSERT INTO [Tasks] ([BeginTime], [EndTime], [Name], [Description], [Place])" +
                           "VALUES (@BeginTime, @EndTime, @Name, @Description, @Place);" +
                           "SELECT SCOPE_IDENTITY();";

            using (SqlConnection connection = new SqlConnection(_connectionString))
            using (SqlCommand command = new SqlCommand(query, connection))
            {
                connection.Open();

                command.Parameters.AddWithValue("@BeginTime", task.BeginTime);
                command.Parameters.AddWithValue("@EndTime", task.EndTime);
                command.Parameters.AddWithValue("@Name", task.Name);
                command.Parameters.AddWithValue("@Description", task.Description);
                command.Parameters.AddWithValue("@Place", task.Place);

                return Convert.ToInt32(command.ExecuteScalar().ToString());
            }
        }
Example #2
0
 /// <summary>
 /// Добавление записи в DataGridView.
 /// </summary>
 /// <param name="task">Добавляемая задача.</param>
 /// <param name="recordId">Id добавляемой записи.</param>
 private void AddRecordToDataGridView(Task task, int recordId)
 {
     DataTable dataTable = (DataTable) _dataGridView.DataSource;
     dataTable.Rows.Add(recordId, task.BeginTime, task.EndTime, task.Name, task.Description, task.Place);
 }