ramrodcar
asked on
ImportRow is not Importing the row
Why won't this work, no errors or anything, but it never adds the row to tablename * "_Agg"
The row is filled and populated with values before the importrow, so i don't know why this isn't working.
For Each tTable As ds17_MSByCat.spMMC17_Marke tShareByCa tDataTable In ds.Tables
Dim tNewRow As ds17_MSByCat.spMMC17_Marke tShareByCa tRow = tTable.NewRow
If tTable.TableName <> "spMMC17_MarketShareByCat" And Right(tTable.TableName, 3) <> "Agg" Then
tNewRow = tTable.NewRow
For Each row As ds17_MSByCat.spMMC17_Marke tShareByCa tRow In tTable.Rows
tNewRow.Item("txtSegment") = row.Item("txtSegment").ToS tring
tNewRow.Item("txtManufactu ringFamily ") = row.Item("txtManufacturing Family").T oString
tNewRow.Item("txtYearBiAnn ual") = row.Item("txtYearBiAnnual" ).ToString
tNewRow.Item("intCatUnits" ) += CInt(row.Item("intCatUnits ").ToStrin g)
tNewRow.Item("intCatDollar s") += CInt(row.Item("intCatDolla rs").ToStr ing)
tNewRow.Item("intHomeUnits ") += CInt(row.Item("intHomeUnit s").ToStri ng)
tNewRow.Item("intHomeDolla rs") += CInt(row.Item("intHomeDoll ars").ToSt ring)
Next row
tNewRow.Item("dblUnitMS") = IIf(tNewRow("intCatUnits") = 0, 0, tNewRow("intHomeUnits") / tNewRow("intCatUnits"))
tNewRow.Item("dblDollarMS" ) = IIf(tNewRow("intCatDollars ") = 0, 0, tNewRow("intHomeDollars") / tNewRow("intCatDollars"))
ds.Tables(tTable.TableName & "_Agg").ImportRow(tNewRow)
End If
Next tTable
The row is filled and populated with values before the importrow, so i don't know why this isn't working.
For Each tTable As ds17_MSByCat.spMMC17_Marke
Dim tNewRow As ds17_MSByCat.spMMC17_Marke
If tTable.TableName <> "spMMC17_MarketShareByCat"
tNewRow = tTable.NewRow
For Each row As ds17_MSByCat.spMMC17_Marke
tNewRow.Item("txtSegment")
tNewRow.Item("txtManufactu
tNewRow.Item("txtYearBiAnn
tNewRow.Item("intCatUnits"
tNewRow.Item("intCatDollar
tNewRow.Item("intHomeUnits
tNewRow.Item("intHomeDolla
Next row
tNewRow.Item("dblUnitMS") = IIf(tNewRow("intCatUnits")
tNewRow.Item("dblDollarMS"
ds.Tables(tTable.TableName
End If
Next tTable
ImportRow is meant to add a DataRow to a DataTable from another DataTable instance. If you are just creating new rows, and wanting to add them to a DataTable, then you just need to use DataTable.Rows.Add(newRow) .
Bob
Bob
ASKER
i cannot addrow because the the primary keys in the underlying data has only one row, the one row added to the aggregate table is the same as the single row in the originating table.
ASKER
forget what i said about primary keys, with one row of data in the non _Agg table, when that is aggregated and thrown into the aggregate table, they are the same.
tNewRow doesn't belong to any table, so you can't import it to ds.Tables(tTable.TableName & "_Agg").
I don't understand what you are trying to do. Are you trying to create a single-row aggregate table for a GridView?
Bob
I don't understand what you are trying to do. Are you trying to create a single-row aggregate table for a GridView?
Bob
ASKER
i am binding this to a data list.. Lets say i have a base table called "ProductX" with 5 rows, and an aggregate table named "ProductX_Agg" (which will only hold 1 row, the aggregate totals)..
So if table "ProductX" has only 1 row, then the 1 aggregate row that is going to be added to "ProductX_Agg" will be the same as the one row in "ProductX" hence causing an error about the row belonging to another table when using rows.add(tnewRow), because they are the same value.. But if "ProductX" has more than 1 row, there will never be a problem as the one row we're aggregating to put in "ProductX_Agg" will never equal one single row in "ProductX"
So if table "ProductX" has only 1 row, then the 1 aggregate row that is going to be added to "ProductX_Agg" will be the same as the one row in "ProductX" hence causing an error about the row belonging to another table when using rows.add(tnewRow), because they are the same value.. But if "ProductX" has more than 1 row, there will never be a problem as the one row we're aggregating to put in "ProductX_Agg" will never equal one single row in "ProductX"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
excellent, can you help me with this one now? https://www.experts-exchange.com/questions/22894708/Help-with-Nested-DataList.html
:)
:)
ASKER