Link to home
Start Free TrialLog in
Avatar of ramrodcar
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_MarketShareByCatDataTable In ds.Tables
                Dim tNewRow As ds17_MSByCat.spMMC17_MarketShareByCatRow = tTable.NewRow
                If tTable.TableName <> "spMMC17_MarketShareByCat" And Right(tTable.TableName, 3) <> "Agg" Then
                    tNewRow = tTable.NewRow
                    For Each row As ds17_MSByCat.spMMC17_MarketShareByCatRow In tTable.Rows
                        tNewRow.Item("txtSegment") = row.Item("txtSegment").ToString
                        tNewRow.Item("txtManufacturingFamily") = row.Item("txtManufacturingFamily").ToString
                        tNewRow.Item("txtYearBiAnnual") = row.Item("txtYearBiAnnual").ToString
                        tNewRow.Item("intCatUnits") += CInt(row.Item("intCatUnits").ToString)
                        tNewRow.Item("intCatDollars") += CInt(row.Item("intCatDollars").ToString)
                        tNewRow.Item("intHomeUnits") += CInt(row.Item("intHomeUnits").ToString)
                        tNewRow.Item("intHomeDollars") += CInt(row.Item("intHomeDollars").ToString)
                    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
Avatar of ramrodcar
ramrodcar

ASKER

this is basically taking a group of tables, iterating through each row of those tables and aggregating them, then when it hits the last row, appends them to a new table that holds the aggregate values.
Avatar of Bob Learned
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
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.
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 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"
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial