EDN Admin
Well-known member
<span style="color:#222222; font-familyroid Serif,Georgia,Times New Roman,serif; font-size:14px; line-height:23px Good day to the community<br style="font-size:14px; font-familyroid Serif,Georgia,Times New Roman,serif; color:#222222; line-height:23px
<br style="font-size:14px; font-familyroid Serif,Georgia,Times New Roman,serif; color:#222222; line-height:23px
<span style="color:#222222; font-familyroid Serif,Georgia,Times New Roman,serif; font-size:14px; line-height:23px First, please be patient, as Im a french native. My english may not be perfect.<br style="font-size:14px; font-familyroid Serif,Georgia,Times New Roman,serif; color:#222222; line-height:23px
<br style="font-size:14px; font-familyroid Serif,Georgia,Times New Roman,serif; color:#222222; line-height:23px
<span style="color:#222222; font-familyroid Serif,Georgia,Times New Roman,serif; font-size:14px; line-height:23px Ive been searching over the web for an answer, but in vain.<br style="font-size:14px; font-familyroid Serif,Georgia,Times New Roman,serif; color:#222222; line-height:23px
<br style="font-size:14px; font-familyroid Serif,Georgia,Times New Roman,serif; color:#222222; line-height:23px
<span style="color:#222222; font-familyroid Serif,Georgia,Times New Roman,serif; font-size:14px; line-height:23px I have a DataSet which gets Data from my Database. I have strongly named DataTable into it which contains the data I fetch. Its about vehicle
makes and models ( Mark_Table and Model_Table) with a foreign key link the 2 tables (multiple Models for a specific Make).<br style="font-size:14px; font-familyroid Serif,Georgia,Times New Roman,serif; color:#222222; line-height:23px
<br style="font-size:14px; font-familyroid Serif,Georgia,Times New Roman,serif; color:#222222; line-height:23px
<span style="color:#222222; font-familyroid Serif,Georgia,Times New Roman,serif; font-size:14px; line-height:23px Filling the tables and editing the content doesnt seems to be a problem. My problem lies in the following code.
<pre class="prettyprint" style=" MyDBDataSet.Model_tableDataTable deletedRows = (MyDBDataSet.Model_tableDataTable)MyDataSet.Model_table.GetChanges(DataRowState.Deleted);MyDBDataSet.Model_tableDataTable addedRows = (MyDBDataSet.Model_tableDataTable)MyDataSet.Model_table.GetChanges(DataRowState.Added);
MyDBDataSet.Model_tableDataTable editedRows = (MyDBDataSet.Model_tableDataTable)MyDataSet.Model_table.GetChanges(DataRowState.Modified);
//Delete Model Table
if (deletedRows != null)
model_tableTableAdapter.Update(deletedRows);
//Update Make Table
mark_tableTableAdapter.Update(MyDBDataSet.Mark_table);
//Add Model Table
if (addedRows != null)
model_tableTableAdapter.Update(addedRows);
//Modify Model Table
if (editedRows != null)
model_tableTableAdapter.Update(editedRows);
MyDataSet.AcceptChanges();[/code]
<pre class="prettyprint" style=" <span style="color:#222222; font-familyroid Serif,Georgia,Times New Roman,serif; font-size:14px; line-height:23px I keep getting a "The INSERT statement conflicted with the FOREIGN KEY constraint MyForeignKey_Model_table_<wbr style="font-size:14px; font-familyroid Serif,Georgia,Times New Roman,serif; color:#222222; line-height:23px <span style="color:#222222; font-familyroid Serif,Georgia,Times New Roman,serif; font-size:14px; line-height:23px blablabla<wbr style="font-size:14px; font-familyroid Serif,Georgia,Times New Roman,serif; color:#222222; line-height:23px <span style="color:#222222; font-familyroid Serif,Georgia,Times New Roman,serif; font-size:14px; line-height:23px .
The conflict occured in database MyDataBase, table Mark_Table, column Mark_id. The statement has been terminated.<br/>[/code]
<br style="font-size:14px; font-familyroid Serif,Georgia,Times New Roman,serif; color:#222222; line-height:23px
<span style="color:#222222; font-familyroid Serif,Georgia,Times New Roman,serif; font-size:14px; line-height:23px This happens when I add a Make in the Mark_Table then when I add models to the Model_Table in relation to that previous Make.<br style="font-size:14px; font-familyroid Serif,Georgia,Times New Roman,serif; color:#222222; line-height:23px
<br style="font-size:14px; font-familyroid Serif,Georgia,Times New Roman,serif; color:#222222; line-height:23px
<span style="color:#222222; font-familyroid Serif,Georgia,Times New Roman,serif; font-size:14px; line-height:23px The error is similar when I tried to delete a Make tied with Models.<br style="font-size:14px; font-familyroid Serif,Georgia,Times New Roman,serif; color:#222222; line-height:23px
<span style="color:#222222; font-familyroid Serif,Georgia,Times New Roman,serif; font-size:14px; line-height:23px
<span style="color:#222222; font-familyroid Serif,Georgia,Times New Roman,serif; font-size:14px; line-height:23px I can make every operation one at a time, but thats not my goal. I want all my operations to happen with 1 click, not 50.<br/>
<span style="color:#222222; font-familyroid Serif,Georgia,Times New Roman,serif; font-size:14px; line-height:23px
<span style="color:#222222; font-familyroid Serif,Georgia,Times New Roman,serif; font-size:13px; line-height:20px The mark_tableTableAdapter and the model_tableTableAdapter are declared in the designer view, which is why you wont see it here. The
code provided is where the error is found. As for filling information in the dataset, I have no problem. I am using the same procedure for other tables of my database, but they are not in relations to another table. It works everywhere else other than here.<br style="font-size:13px; font-familyroid Serif,Georgia,Times New Roman,serif; color:#222222; line-height:20px
<br style="font-size:13px; font-familyroid Serif,Georgia,Times New Roman,serif; color:#222222; line-height:20px
<span style="color:#222222; font-familyroid Serif,Georgia,Times New Roman,serif; font-size:13px; line-height:20px For clarification, I have in a winform two DataGridView, one for Makes and one for Models. I have several TextBox and Button which works
in the actual tables, wether its adding, editing or deleting rows.<br style="font-size:13px; font-familyroid Serif,Georgia,Times New Roman,serif; color:#222222; line-height:20px
<br style="font-size:13px; font-familyroid Serif,Georgia,Times New Roman,serif; color:#222222; line-height:20px
<span style="color:#222222; font-familyroid Serif,Georgia,Times New Roman,serif; font-size:13px; line-height:20px * When I delete a Make which is linked to multiple Models, I loop through the Models, then Delete() them from the DataTable before I Delete()
the Make from the DataTable.<br style="font-size:13px; font-familyroid Serif,Georgia,Times New Roman,serif; color:#222222; line-height:20px
<br style="font-size:13px; font-familyroid Serif,Georgia,Times New Roman,serif; color:#222222; line-height:20px
<span style="color:#222222; font-familyroid Serif,Georgia,Times New Roman,serif; font-size:13px; line-height:20px The information is bound to two DataGridView, and its in the Smart Task Panel that I assign the DataSource. The TableAdapters were created
automatically.<br style="font-size:13px; font-familyroid Serif,Georgia,Times New Roman,serif; color:#222222; line-height:20px
<br/>
<span style="color:#222222; font-familyroid Serif,Georgia,Times New Roman,serif; font-size:14px; line-height:23px
<br/>
<br/>
<br/>
View the full article
<br style="font-size:14px; font-familyroid Serif,Georgia,Times New Roman,serif; color:#222222; line-height:23px
<span style="color:#222222; font-familyroid Serif,Georgia,Times New Roman,serif; font-size:14px; line-height:23px First, please be patient, as Im a french native. My english may not be perfect.<br style="font-size:14px; font-familyroid Serif,Georgia,Times New Roman,serif; color:#222222; line-height:23px
<br style="font-size:14px; font-familyroid Serif,Georgia,Times New Roman,serif; color:#222222; line-height:23px
<span style="color:#222222; font-familyroid Serif,Georgia,Times New Roman,serif; font-size:14px; line-height:23px Ive been searching over the web for an answer, but in vain.<br style="font-size:14px; font-familyroid Serif,Georgia,Times New Roman,serif; color:#222222; line-height:23px
<br style="font-size:14px; font-familyroid Serif,Georgia,Times New Roman,serif; color:#222222; line-height:23px
<span style="color:#222222; font-familyroid Serif,Georgia,Times New Roman,serif; font-size:14px; line-height:23px I have a DataSet which gets Data from my Database. I have strongly named DataTable into it which contains the data I fetch. Its about vehicle
makes and models ( Mark_Table and Model_Table) with a foreign key link the 2 tables (multiple Models for a specific Make).<br style="font-size:14px; font-familyroid Serif,Georgia,Times New Roman,serif; color:#222222; line-height:23px
<br style="font-size:14px; font-familyroid Serif,Georgia,Times New Roman,serif; color:#222222; line-height:23px
<span style="color:#222222; font-familyroid Serif,Georgia,Times New Roman,serif; font-size:14px; line-height:23px Filling the tables and editing the content doesnt seems to be a problem. My problem lies in the following code.
<pre class="prettyprint" style=" MyDBDataSet.Model_tableDataTable deletedRows = (MyDBDataSet.Model_tableDataTable)MyDataSet.Model_table.GetChanges(DataRowState.Deleted);MyDBDataSet.Model_tableDataTable addedRows = (MyDBDataSet.Model_tableDataTable)MyDataSet.Model_table.GetChanges(DataRowState.Added);
MyDBDataSet.Model_tableDataTable editedRows = (MyDBDataSet.Model_tableDataTable)MyDataSet.Model_table.GetChanges(DataRowState.Modified);
//Delete Model Table
if (deletedRows != null)
model_tableTableAdapter.Update(deletedRows);
//Update Make Table
mark_tableTableAdapter.Update(MyDBDataSet.Mark_table);
//Add Model Table
if (addedRows != null)
model_tableTableAdapter.Update(addedRows);
//Modify Model Table
if (editedRows != null)
model_tableTableAdapter.Update(editedRows);
MyDataSet.AcceptChanges();[/code]
<pre class="prettyprint" style=" <span style="color:#222222; font-familyroid Serif,Georgia,Times New Roman,serif; font-size:14px; line-height:23px I keep getting a "The INSERT statement conflicted with the FOREIGN KEY constraint MyForeignKey_Model_table_<wbr style="font-size:14px; font-familyroid Serif,Georgia,Times New Roman,serif; color:#222222; line-height:23px <span style="color:#222222; font-familyroid Serif,Georgia,Times New Roman,serif; font-size:14px; line-height:23px blablabla<wbr style="font-size:14px; font-familyroid Serif,Georgia,Times New Roman,serif; color:#222222; line-height:23px <span style="color:#222222; font-familyroid Serif,Georgia,Times New Roman,serif; font-size:14px; line-height:23px .
The conflict occured in database MyDataBase, table Mark_Table, column Mark_id. The statement has been terminated.<br/>[/code]
<br style="font-size:14px; font-familyroid Serif,Georgia,Times New Roman,serif; color:#222222; line-height:23px
<span style="color:#222222; font-familyroid Serif,Georgia,Times New Roman,serif; font-size:14px; line-height:23px This happens when I add a Make in the Mark_Table then when I add models to the Model_Table in relation to that previous Make.<br style="font-size:14px; font-familyroid Serif,Georgia,Times New Roman,serif; color:#222222; line-height:23px
<br style="font-size:14px; font-familyroid Serif,Georgia,Times New Roman,serif; color:#222222; line-height:23px
<span style="color:#222222; font-familyroid Serif,Georgia,Times New Roman,serif; font-size:14px; line-height:23px The error is similar when I tried to delete a Make tied with Models.<br style="font-size:14px; font-familyroid Serif,Georgia,Times New Roman,serif; color:#222222; line-height:23px
<span style="color:#222222; font-familyroid Serif,Georgia,Times New Roman,serif; font-size:14px; line-height:23px
<span style="color:#222222; font-familyroid Serif,Georgia,Times New Roman,serif; font-size:14px; line-height:23px I can make every operation one at a time, but thats not my goal. I want all my operations to happen with 1 click, not 50.<br/>
<span style="color:#222222; font-familyroid Serif,Georgia,Times New Roman,serif; font-size:14px; line-height:23px
<span style="color:#222222; font-familyroid Serif,Georgia,Times New Roman,serif; font-size:13px; line-height:20px The mark_tableTableAdapter and the model_tableTableAdapter are declared in the designer view, which is why you wont see it here. The
code provided is where the error is found. As for filling information in the dataset, I have no problem. I am using the same procedure for other tables of my database, but they are not in relations to another table. It works everywhere else other than here.<br style="font-size:13px; font-familyroid Serif,Georgia,Times New Roman,serif; color:#222222; line-height:20px
<br style="font-size:13px; font-familyroid Serif,Georgia,Times New Roman,serif; color:#222222; line-height:20px
<span style="color:#222222; font-familyroid Serif,Georgia,Times New Roman,serif; font-size:13px; line-height:20px For clarification, I have in a winform two DataGridView, one for Makes and one for Models. I have several TextBox and Button which works
in the actual tables, wether its adding, editing or deleting rows.<br style="font-size:13px; font-familyroid Serif,Georgia,Times New Roman,serif; color:#222222; line-height:20px
<br style="font-size:13px; font-familyroid Serif,Georgia,Times New Roman,serif; color:#222222; line-height:20px
<span style="color:#222222; font-familyroid Serif,Georgia,Times New Roman,serif; font-size:13px; line-height:20px * When I delete a Make which is linked to multiple Models, I loop through the Models, then Delete() them from the DataTable before I Delete()
the Make from the DataTable.<br style="font-size:13px; font-familyroid Serif,Georgia,Times New Roman,serif; color:#222222; line-height:20px
<br style="font-size:13px; font-familyroid Serif,Georgia,Times New Roman,serif; color:#222222; line-height:20px
<span style="color:#222222; font-familyroid Serif,Georgia,Times New Roman,serif; font-size:13px; line-height:20px The information is bound to two DataGridView, and its in the Smart Task Panel that I assign the DataSource. The TableAdapters were created
automatically.<br style="font-size:13px; font-familyroid Serif,Georgia,Times New Roman,serif; color:#222222; line-height:20px
<br/>
<span style="color:#222222; font-familyroid Serif,Georgia,Times New Roman,serif; font-size:14px; line-height:23px
<br/>
<br/>
<br/>
View the full article