Hello. I solve the following problem:
There is an Access database of two related tables (one-to-many relationship; one row of table1 corresponds to several rows of table2). There are two datadds on the form to display both database tables.
It is necessary to implement the function of deleting data from the database (and accordingly from data nodes) that works as follows: when deleting a selected row from the main table (dataGridView1), also delete all its related rows from the second table (dataGridView2).
I compiled this method, but it deletes through a stump-deck, I do not see the logic in its deletions ((What is the cant?
private void buttonDeleteMainTable_Click(object sender, EventArgs e) { if (MessageBox.Show("Удалить запись?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { string str; str = Convert.ToString(dataGridView1.CurrentRow.Cells[0].Value);//захват значения индекса записи из первой таблицы for (int i = 0; i < dataGridView2.RowCount; i++) { if (dataGridView2.Rows[i].Cells[1].Value.ToString() == str) { dataGridView2.Rows[i].Selected = true; nameFirmModelParamBindingSource.RemoveCurrent(); model_ParamTableAdapter.Update(dataBaseMDBDataSet._Model_Param); } } nameFirmBindingSource.RemoveCurrent(); name_FirmTableAdapter.Update(dataBaseMDBDataSet.Name_Firm); } }