Results 1 to 37 of 37

Thread: [RESOLVED] Want to hijack a SqlDataReader class so it can be sourced from multiple places

Threaded View

  1. #1

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Resolved [RESOLVED] Want to hijack a SqlDataReader class so it can be sourced from multiple places

    Ok - I'm using a simple SqlDataReader like this:

    Code:
    Using rsPrint As SqlDataReader = cmd.ExecuteReader
    
        ReDim strRS(0 To rsPrint.FieldCount - 1, 0 To 2)
    .
    .
    .
        If rsPrint.HasRows Then
            If rsPrint.GetName(0) = "%%errormessage%%" Then
                strErrorMessage = rsPrint(0)
    .
    .
    .
            End If
        End If
    Simple stuff - using for example: .FieldCount, .HasRows, .GetName and more important, the default method which just returns a field (rsPrint(0) near the bottom of that code snippet).

    What I'm looking to do is allow for this existing SQL access - calling that ExecuteReader at the top to work but also allow the "source" of the data to be a local array.

    I'm thinking I can "override" each method and property to either "call the underlying" SqlDataReader code, or "use" my own code that is managing the local array instead.

    I'm looking to not change any of the code in this Using Block - basically transparently source rsPrint from two different places.

    I know how to do this in JavaScript - and believe I've seen it done here before.

    I'm using VS 2012 unfortunately.

    TIA! Steve
    Last edited by szlamany; Feb 25th, 2021 at 05:05 PM.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width