Domanda

I've hit a problem with my database. The purpose of the section of my application is simple this; when a user marks an assignment of work complete, it will transfer one DataRow from "activeUnits" by using the "table.ImportRow" method to another table called "completedUnits" and then use the table adapter to update this change to the core database. However when testing this function the Dataset has completed the move of rows successfully internally, but upon using the TableAdapter.Update method the update of data to the database returns simply as "0" with no changes made or errors to lead.

                Try
                        Dim activeRowMove As DataRow = Me.AssignmentDataSet.activeUnits.Rows(currentIndex)
                        Dim newMove As DataTable = Me.AssignmentDataSet.completedUnits



                        newMove.ImportRow(activeRowMove)


                        'UPDATE CHANGES
                        Me.Validate()
                        CompletedUnitsBindingSource.EndEdit()
                        Console.WriteLine(Me.CompletedUnitsTableAdapter.Update(Me.AssignmentDataSet.completedUnits))

                        activeUnitsTitle.Text = ("Assignment Completed!")

                    Catch ex As Exception
                        Console.WriteLine("Failed to update new table: " & ex.ToString)
                        activeUnitsTitle.Text = ("Failed to save!")

                    End Try

Is there somewhere in my code which I've simply done wrong, or any better or efficient way of moving a datarow is appreciated!

My database is not copied in my project's bin folder and every update goes to one central location.

If needed the following link is two screenshots of my current layout and data - here.

È stato utile?

Soluzione

From MSDN:

Calling ImportRow preserves the existing DataRowState along with other values in the row

So, if the DataRowState in your "from" table is Unchanged, then its state will remained Unchanged in the "to" table, and it will not get saved.

Make sure to change the DataRowState of the newly imported row to Added

Cheers

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top