开发者

For Each Next loop getting first row data only

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

If I try to change it to use dr instead of bo , it wont accept it.

I get:

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

If I try using DS_C.Tbl_ARow

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

I get type 'DS_C.Tbl_ARow' is not defined

If I try :

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

I get:

System.InvalidCastException = {"Unable to cast object of type 'System.Data.DataRow' to type 'TblXLMajorPerilsRow'."} 


You need to access it like this:

.CustomerID = dr("CustomerID");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜