Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > System.ArgumentException: This row already belongs to another table.
 

System.ArgumentException: This row already belongs to another table.

I am trying to add rows from dsActiveNewAlarms
to dsActiveNewAlarms I am getting the error row already exists
in fact row which I am trying to add is totally new row

Where a is the total number of rows in  dsActiveNewAlarms
 

Dim oRow As DataRow

Do While m < a

oRow = dsActiveAlarms.Tables(0).NewRow

oRow = dsActiveNewAlarms.Tables(0).Rows(m)

dsActiveAlarms.Tables(0).Rows.Add(oRow)

m = m + 1

Loop
MigrationUser 1  Tuesday, December 28, 2004 4:18 PM
get rid of this line 

oRow = dsActiveAlarms.Tables(0).NewRow 

and make it something like

oRow = dsActiveNewAlarms.Tables(0).NewRow 

HTH, let us know
MigrationUser 1  Tuesday, December 28, 2004 4:24 PM
I think it will not work........

To get rid of this u have to do something like this.............


Dim oRow As DataRow 
dim intColCounter as integer

Do While m < a 

oRow = dsActiveAlarms.Tables(0).NewRow 

for intColCounter =0 to dsActiveNewAlarms.Tables(0).Column.Count-1
        oRow(intColCounter ) = dsActiveNewAlarms.Tables(0).Rows(m) .Item(intColCounter )
Next

dsActiveAlarms.Tables(0).Rows.Add(oRow) 

m = m + 1 

Loop 




MigrationUser 1  Wednesday, December 29, 2004 9:29 AM
I had fixed this problem with the following code. But now I am facing with another problem, I don't want to add the duplicate rows

Try
 Dim ieRows As IEnumerator = dsActiveNewAlarms.Tables(0).Rows.GetEnumerator
 Dim drow As DataRow
 While ieRows.MoveNext

  drow = CType(ieRows.Current, DataRow)
  dsActiveAlarms.Tables(0).LoadDataRow(drow.ItemArray, True)

 End While

Catch ex As Exception
     MsgBox(ex.ToString())
End Try


With the above code I am adding the row from one dataset to another
Before adding the row I want to check whether the row already
exists in the dataset, if it exist then I don't want to add it
MigrationUser 1  Tuesday, January 04, 2005 2:42 PM

You can use google to search for other answers

Custom Search

More Threads

• UserControl in a DataGridView Cell
• how to handle connection.StateChange
• Fix for DGV DataError
• Problem with Datagridview ColumnHeaderMouseClick
• IErrorInfo.GetDescription failed with E_FAIL(0x80004005)
• using XSD to convert objects?
• Another ComboBox Quandry!
• Disconnected Architecture
• Is there a better way to do this??
• cannot reuse an existing typed dataset in presentation project without having to use WCF