Rows are added by reference. You will need to call the copy function on the
row so that a copy can be returned which you then add to your new database.
> (!!! So what.... I want to add it to a new DS... ???? weird.. why restrict
> a developer??)
"Neal Rogers via .NET 247" <anonymous@dotnet247.com> wrote in message
news:eActaH7KFHA.3992@TK2MSFTNGP15.phx.gbl...
> hi
>
> I am trying to create a new DS from an incoming (ex DBase query).
> The Incoming one has data, which spawns (should) multiple records,
> depending on the data in the pertinent field.
> ie Incoming has 18 rows, 6 of which indicate the need to create 2 - 7 new
> rows, and drop that old incoming row.
>
> I try creating a ds based on the incoming one.
> Then iterating thru the old one, and where the data dictates, calling a
> rtn which appends new rows (actually a copy of the old row, with the
> necessary changes made to it's data, and appended to the new DS, but..
> I usually get
> "Error: this row already belongs to another table" ...
> (!!! So what.... I want to add it to a new DS... ???? weird.. why restrict
> a developer??)
>
> So... anybody ??
>
> To clarify .. heres the code.
>
> private shared _NewDs as DataSet
>
> Function xxx(byval In_ds as dataset) as dataset
> Dim dr As DataRow
> Dim i As Integer
>
> _NewDs.Merge(In_DS) 'or _NewDs = ActsLocsDaysIn_DS
>
> For i = 0 To ActsLocsDaysIn_DS.Tables(0).Rows.Count - 1
> dr = ActsLocsDaysIn_DS.Tables(0).Rows(i)
>
> If Not IsDBNull(dr.Item("sugDay")) Then
> Select Case Trim(dr.Item("sugDay"))
> Case "U" 'WTF
> ReplaceAppendSuggestedDays(dr, "3,4,5")
> Case "V" 'M,WTF
> ReplaceAppendSuggestedDays(dr, "1,3,4,5")
> Case Else
> 'nothing
> End Select
> Else
> 'Nothing
> End If
> Next
>
> Return _NewDs
> end function
>
> Private Shared Sub ReplaceAppendSuggestedDays(ByVal drIn As DataRow,
> ByVal sDays As String)
> Dim drNew As DataRow
> Dim sArr() As String = Split(sDays, ",")
> Dim i As Integer
> Dim iNumDaysReqd As Integer = UBound(sArr)
>
> Try
> drNew = drIn
> For i = 0 To iNumDaysReqd - 1
> 'Insert new rows per suggested day (1 "U" row ) suggests 4
> new rows
> If sArr(i) = "1" Then ' Monday
> drNew.Item("sugDay") = "1"
> ElseIf sArr(i) = "2" Then ' Tuesday
> drNew.Item("sugDay") = "2"
> ElseIf sArr(i) = "3" Then ' Wednesday
> drNew.Item("sugDay") = "4"
> ElseIf sArr(i) = "4" Then ' Thursday
> drNew.Item("sugDay") = "8"
> ElseIf sArr(i) = "5" Then ' Friday
> drNew.Item("sugDay") = "G"
> ElseIf sArr(i) = "6" Then ' Saturday
> drNew.Item("sugDay") = "W"
> ElseIf sArr(i) = "7" Then ' Sunday
> drNew.Item("sugDay") = "1S"
> End If
> drNew.AcceptChanges()
> AppendToDS(drNew)
> Next
> Catch er As Exception
> Throw New Exception("Error AppendSugDays : " & er.Message)
> End Try
> End Sub
>
> Private Shared Sub AppendToDS(ByVal drnew As DataRow)
> _NewDs.Tables(0).Rows.Add(drnew)
> End Sub
>
> -------------------------------
> From: Neal Rogers
>
> -----------------------
> Posted by a user from .NET 247 (
http://www.dotnet247.com/)
>
> <Id>DId7ArLIIkat6Re6Sok4Bg==</Id>