简体   繁体   中英

How to fix late binding for datarow in datacollection where datarow variable defined in range

I'm in the process of converting VB to C#.Net for my company. In order to do this more easily, I have option strict ON. I am trying to resolve a late binding on the following code. Row is considered an OBJECT by the compiler. I've never written code in this fashion (someone else's work). Here is the code.

        Dim items As List(Of Contact) = ContactsTable.GetChanges.DataTableToList(Of Contact)
    'Dim row As DataRow = Nothing
    Dim modifiedRows As DataRowCollection = From row In ContactsTable.Rows
                       Where row.RowState = DataRowState.Modified Or row.RowState = DataRowState.Added

There was no way to modify the existing code. The next best option was to recode it using a "For each" loop.

        Dim modifiedRows As DataRowCollection = Nothing
    For each row As DataRow In ContactsTable.Rows
        If row.RowState = DataRowState.Modified Or row.RowState = DataRowState.Added Then
            modifiedRows.Add(row)
        End If
    Next

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM