Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

ImportRow is not Importing the row

Posted on 2007-10-15
8
Medium Priority
?
1,155 Views
Last Modified: 2013-11-07
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
0
Comment
Question by:ramrodcar
  • 5
  • 3
8 Comments
 

Author Comment

by:ramrodcar
ID: 20080769
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.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 20080828
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
0
 

Author Comment

by:ramrodcar
ID: 20080839
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.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:ramrodcar
ID: 20080847
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.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 20081040
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
0
 

Author Comment

by:ramrodcar
ID: 20081228
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"
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 2000 total points
ID: 20082721
1) You creating new rows for tTable here:

    tNewRow = tTable.NewRow

2) You won't get the error about the row belonging to a table, if you create a new row from the ProductX_Agg table instead of the ProductX table.

    tNewRow = ds.Tables(tTable.TableName & "_Agg").NewRow()

Bob
0
 

Author Comment

by:ramrodcar
ID: 20085396
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question