Robert Blot

Robert Blot

  • NA
  • 10
  • 12.3k

This row already belongs to another table

May 14 2012 5:59 PM
When I try to update a record I get an error saying that the row already belongs to another table. I am accessing a specific table to update this record. This is the code for the update. The Project table updates ok. It's the Printer table that throws the error

Private Sub ActionUpdate()
 
        Try
            Select Case tabCodeLevels.SelectedTab.Text
                Case "Projects"
                    Using objProjects As New CodeLevelsBusinessLogic.Project_BL( _
                            strCompany, strApplication)
 
                        objDataSet = objProjects.GetNewProjectDS()
 
                        Dim objDataRow As Data.DataRow = objDataSet.Tables("Project").NewRow
 
                        objDataRow.Item("Project_ID") = New Guid(txtProjectID.Text)
                        objDataRow.Item("Project_Type") = cboProjectType.SelectedItem
                        objDataRow.Item("Project_Status") = cboProjectStatus.SelectedItem
                        objDataRow.Item("Project_CodeLevel") = cboProjectCodeLevel.SelectedItem
                        objDataRow.Item("Project_CodeType") = cboProjectCodeType.SelectedItem
                        objDataRow.Item("Project_Name") = txtProjectName.Text
                        objDataRow.Item("Project_Lead") = txtProjectLead.Text
                        objDataRow.Item("Project_Engineer") = txtProjectEngineer.Text
                        objDataRow.Item("Project_Technician") = txtProjectTechnician.Text
                        objDataRow.Item("Project_SwFwEngineer") = txtProjectSwFwEngineer.Text
                        objDataRow.Item("Project_SwFwTechnician") = txtProjectSwFwTechnician.Text
                        objDataRow.Item("Project_Description") = txtProjectDescription.Text
                        objDataRow.Item("Project_Notes") = txtProjectNotes.Text
                        objDataRow.Item("Project_Date_Added") = dtpProjectDateAdded.Text
                        objDataRow.Item("Project_Last_Modified") = dtpProjectLastModified.Text
 
                        objDataSet.Tables("Project").Rows.Add(objDataRow)
 
                        If Not objProjects.UpdateProject(objDataSet) Then
                            Throw New Exception("Update Project failed")
                        End If
 
                    End Using
 
                Case "Printers"
                    Using objPrinters As New CodeLevelsBusinessLogic.PrinterBL( _
                        strCompany, strApplication)
 
                        objDataSet = objPrinters.GetNewPrinterDS()
 
                        Dim objDataRow As Data.DataRow = objPrintersDS.Tables("Printer").NewRow
 
                        objDataRow.Item("PrinterProject_Name") = cboPrinterProjectName.SelectedItem
                        objDataRow.Item("PrinterProject_ID") = New Guid(txtPrinterProjectID.Text)
                        objDataRow.Item("Printer_ID") = New Guid(txtPrinterID.Text)
                        objDataRow.Item("Printer_Status") = cboPrinterStatus.SelectedItem
                        objDataRow.Item("Printer_Name") = txtPrinterName.Text
                        objDataRow.Item("Printer_SerialNumber") = txtPrinterSerialNumber.Text
                        objDataRow.Item("Printer_ProcessorID") = txtPrinterProcessorID.Text
                        objDataRow.Item("Printer_Architecture") = cboPrinterArchitecture.SelectedItem
                        objDataRow.Item("Printer_Category") = cboPrinterCategory.SelectedItem
                        objDataRow.Item("Printer_Model") = cboPrinterModel.SelectedItem
                        objDataRow.Item("Printer_Phase") = cboPrinterPhase.SelectedItem
                        objDataRow.Item("Printer_Description") = txtPrinterDescription.Text
                        objDataRow.Item("Printer_Notes") = txtPrinterNotes.Text
                        objDataRow.Item("Printer_Date_Added") = dtpPrinterDateAdded.Text
                        objDataRow.Item("Printer_Last_Modified") = dtpPrinterLastModified.Text
 
                        objDataSet.Tables("Printer").Rows.Add(objDataRow)
 
                        If Not objPrinters.UpdatePrinter(objDataSet) Then
                            Throw New Exception("Update Printer failed.")
                        End If
 
                    End Using
 
                Case "Printer Configuration"
                Case "Printer Debug Options"
                Case "Printer Code Updates"
 
            End Select
 
            fileNew()
            ListViewRefresh()
            codeLevelsToolStripStatus.Text = "Record Updated"
 
        Catch ExceptionErr As Exception
            MessageBox.Show(ExceptionErr.Message, strAppTitle)
 
        End Try
 
    End Sub