Click here to Skip to main content
16,011,815 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to populate a dataset with data from a dynamic SQL dataset created by a code generator (PDSA). If I want the first row of data, or I use a specific "Where" clause to retrieve 1 row, I have no problem. But, when I loop through the dataset that has four entries, instead of getting the four entries, I get the first row 4 times. Any idea why?

Code Example:

Dim DS_C as New DS
Dim dr_A As DS_C.Tbl_ARow

        Me.DS_C.Tbl_A.Clear()

        Dim bo As PDSA.DataLayer.tbl_BDC = New PDSA.BusinessLayer.tbl_B

        With bo
            .ConnectionString = AppConfig.SQLConnectString
            .SelectFilter = PDSA.DataLayer.tbl_BDC.SelectFilters.All
            .WhereFilter = tbl_BDC.WhereFilters.None
            .Load()
        End With

        For Each dr As DataRow In bo.DataSet.Tables(0).Rows

            dr_A = DS_C.Tbl_A.NewRow

            With dr_A
                .CustomerID = bo.CustomerID
                .FirstName = bo.FirstName
                .LastName = bo.LastName
                .Street = bo.Street
                .City = bo.City
                .State = bo.State
                .ZipCode = bo.ZipCode
            End With

            DS_C.Tbl_A.AddTbl_ARow(dr_A)

        Next
Posted

.FirstName = bo.FirstName
            .LastName = bo.LastName
            .Street = bo.Street
            .City = bo.City
            .State = bo.State
            .ZipCode = bo.ZipCode


Instead of using bo here, should it not be using dr?
 
Share this answer
 
Comments
Maciej Los 14-Jul-11 13:02pm    
Good question!
gspeedtech 14-Jul-11 13:31pm    
If I try to change it, it wont accept dr instead of bo

.CustomerID = dr.CustomerID(CustomerID is not a member of System.Data.DataRow)
Using:

.CustomerID = dr("CustomerID")
.FirstName = dr("FirstName")
.LastName = dr("LastName")
.Street = dr("Street") 
.City = dr("City") 
.State = dr("State")
.ZipCode = dr("ZipCode")


instead of .CustomerID = bo.CustomerID etc.
did the trick!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900