Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 908409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:42:52+00:00 2026-05-15T16:42:52+00:00

Note: You may not need to read the whole thing to know what’s wrong…

  • 0

Note: You may not need to read the whole thing to know what’s wrong… skip down to the part about the 3 scenarios if you’d like. Only read the begin if you’d like some background info on how I’ve tried implementing this and where the errors occurred.

To begin with, I’m trying to retrieve a list of Clients stored in the CRM_Clients table for a given callerId.

I retrieve the clients from my Controller with the SelectLiveClientsForCaller method. The message is then passed on to the DAL through the static Instance method in the DataProvider class:

    public List<Client> SelectLiveClientsForCaller(int callerID)
    {
        List<Client> results = new List<Client>();
        IDataReader reader;

        reader = DataProvider.Instance().SelectLiveClientsForCaller(callerID);

        if (reader.Read())
        {
            // If I break here and enumerate the reader, it says that the IEnumerable returned no results
            results = CBO.FillCollection<Client>(reader); // Always comes out as a count of 0
        }

        return results;
    }

My DataProvider class is an abstract class which outlines all the methods the SqlDataProvider has available:

public abstract class DataProvider
{
    // singleton reference to the instantiated object 
    static DataProvider  objProvider = null;

    // constructor
    static DataProvider()
    {
        CreateProvider();
    }

    // dynamically create provider
    private static void CreateProvider()
    {
        objProvider = (DataProvider)Reflection.CreateObject("data", "Owu.Modules.CRM", "");
    }

    // return the provider
    public static  DataProvider Instance() 
    {
        return objProvider;
    }

    public abstract IDataReader SelectLiveClientsForCaller(int callerID);

    /* More abstract methods here... */
}

In the subclass SqlDataProvider the SelectLiveClientsForCaller method is actually handled and calls SqlHelper.ExecuteReader for the stored procedure CRM_Clients_SelectLiveForCaller:

public class SqlDataProvider : DataProvider
{
    private const string ProviderType = "data";
    private ProviderConfiguration _providerConfiguration = ProviderConfiguration.GetProviderConfiguration(ProviderType);
    private string _myConnectionString;
    private string _providerPath;
    private string _objectQualifier;
    private string _databaseOwner;
    private string _moduleQualifier;

    public SqlDataProvider()
    {
        //Read the configuration specific information for this provider
        Provider objProvider = (Provider)_providerConfiguration.Providers[_providerConfiguration.DefaultProvider];

        //Read the attributes for this provider
        //Get Connection string from web.config
        _myConnectionString = Config.GetConnectionString();
    }

    public string MyConnectionString
    {
        get {   return _myConnectionString;   }
    }

    public override IDataReader SelectLiveClientsForCaller(int callerID)
    {
        return (IDataReader)SqlHelper.ExecuteReader(
            myConnectionString,
            "CRM_Clients_SelectLiveForCaller",
            callerID);
    }

    /* More methods here... */
}

Finally, the stored procedure CRM_Clients_SelectLiveForCaller

ALTER PROCEDURE [dbo].[CRM_Clients_SelectLiveForCaller]
@CallerID int
AS
BEGIN
    SET NOCOUNT ON;

    IF @CallerID = -1
    BEGIN
        SELECT * FROM CRM_Clients WHERE IsDeleted = 'false'
    END
    ELSE 
    BEGIN
        SELECT * FROM CRM_Clients WHERE ClientID IN 
            (SELECT ClientID FROM CRM_CallersClients WHERE CallerID = @CallerID)
        AND IsDeleted = 'false'
    END
END

Returns all non-deleted clients for a given callerid.

This should then go back up the line and return results from the controller…

There are 3 scenarios I’ve noticed so far

  1. If there are no records returned from the stored proc (executed through sql server mgmt studio), when calling the sequence of methods reader.Read() returns false and it skips over it completely.

  2. If there is 1 record returned from the stored proc (executed through sql server mgmt studio), when calling the sequence of methods reader.Read() returns true but enumerating the results gives a message saying IEnumerable returned no results

  3. If there are 2 records returned from the stored proc (executed through sql server mgmt studio), when calling the sequence of methods reader.Read() returns true but enumerating the results only returns 1 record instead of 2

Can anyone explain why I’m getting these results for each scenario?

If you need any more info please ask and I’ll update this as soon as I can.

Thanks,
Matt

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T16:42:53+00:00Added an answer on May 15, 2026 at 4:42 pm

    Each call to reader.Read() reads a row, so you are consuming rows just like any IEnumerable caller would consume rows.

    You need to reconsider calling .Read() outside your fill routine to check for existence of rows, because if you call .Read() again inside the fill routine before using the row currently positioned in the reader, you will have lost that first row.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

(note that this question is not about CAS, it's about the May fail spuriously
NOTE: I am aware of the SVN relocate switch, I just need to know
Note - may be more related to computer organization than software, not sure. I'm
Shortly, I want to know if gcc (or g++. I need it in C
I need to read the number of lines in a file before doing some
I need to read/write 16 bytes atomically. I do the writing only using cmpxchg16,
Okay, that may not be the best subject... I am setting up an approval
My question is about a field called contract_nm varchar2(14). I need to get 3
Note that I'm really looking for an answer to my question. I am not
I apologize that the title may not make sense, so let me describe my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.