Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Strange error on DataRow: 'This row already belongs to another table' 2

Status
Not open for further replies.

DotNetter

Programmer
Joined
May 19, 2005
Messages
194
Location
US
When I run the following code:
Code:
	Friend Function FillUsersPropertiesFromDataset(ByVal ds As DataSet) As UserAccountManagerDLL.User()
		If ds.Tables.Count <> 1 Then Exit Function
		If ds.Tables(0).Columns.Contains("PropertyName") = False Then Exit Function
		If ds.Tables(0).Columns.Contains("PropertyValue") = False Then Exit Function

		Dim arrUsers(0) As UserAccountManagerDLL.User
		Dim oUser As UserAccountManagerDLL.User
		Dim oRow As DataRow
		Dim CurrentUserIdentifier As Integer = 0

		Dim dsTemp As New DataSet
		Dim dtTemp As New DataTable
		dsTemp.Tables.Add(dtTemp)

		For Each oRow In ds.Tables(0).Rows
			If CurrentUserIdentifier <> oRow("ClassInstanceIdentifier").ToString And CurrentUserIdentifier <> 0 Then
				CreateUserObjectAndInsertIntoUsersArray(ds, oRow, dsTemp, arrUsers)
			End If

			[b][COLOR=red]dsTemp.Tables(0).Rows.Add(oRow)[/color][/b]
			CurrentUserIdentifier = oRow("ClassInstanceIdentifier")
		Next
		CreateUserObjectAndInsertIntoUsersArray(ds, oRow, dsTemp, arrUsers)

		Return arrUsers

	End Function

I get the following error on the line in red text:
[tt]An unhandled exception of type 'System.ArgumentException' occurred in system.data.dll
Additional information: This row already belongs to another table.[/tt]

How, please, do I remedy this?

Thanks!

Dot
 
Rick, thanks for the reply.

I can't find any [tt]Import[/tt] method at all...

Dot
 
dsTemp.Tables(0).importrow(oRow)


Christiaan Baes
Belgium

I just like this --> [Wiggle] [Wiggle]
 
Thanks so much Rick (and Chrissie, too!) !!!
Dot
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top