Contents tagged with ado.net

  • ADO -> ADO.NET migration

    If you are getting close to actually porting code, I'd recommend also reading Bill Vaughn's take on the subject, Migrating Code and Concepts from ADO "Classic" to ADO.NET. He comes at it from a more conceptual level - "What are your routines in ADO actually doing, and how can you get the same or better functionality in ADO.NET?" Between the two articles you should be able to get the conceptual underpinnings you'll need to get you started.

  • An ease way of using ADO Recordset's Filter method to filter a field by multiple values

    Yesterday, I needed to filter an ADO Recordset field by multiple values, so I first tried:

    'myFilterList = "1,3,4,5"
    If myFilterList & vbNullString <> vbNullString Then
        MyRecordset.Filter = "MyField IN (" & myFilterList & ")"
    End If
    and just found out it did not work because "IN" is not a valid operator for the Filter method. So to workaround this I rewrote code as follow:
    'myFilterList = "1,3,4,5"
    If myFilterList & vbNullString <> vbNullString Then
        MyRecordset.Filter = "MyField = " & Join(Split(myFilterList, ","), " OR MyField = ")
    End If
    Tried it with only one value in the list as below and it also worked correctly
    'myFilterList = "2"
    If myFilterList & vbNullString <> vbNullString Then
        MyRecordset.Filter = "MyField = " & Join(Split(myFilterList, ","), " OR MyField = ")
    End If
    I have not tried it yet with ADO.NET, but believe the problem with the "IN" operator persists. What do you think about this code. Just drop me a line and let me know your opinion about it.