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 6600267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:35:59+00:00 2026-05-25T18:35:59+00:00

I have a stored procedure that, depending on the input, returns multiple rows of

  • 0

I have a stored procedure that, depending on the input, returns multiple rows of ints or multiple rows of DateTimes.

I have looked at the answers to this question and have read and implemented Scott Guthries solution from Handling Multiple Result Shapes from SPROCs (scroll down the page to see that section.)

Unfortunately, it just is not working.

Here is my code:

    [Function(Name = "FunkyStoredProcedure")]
    [ResultType(typeof(List<int>))]
    [ResultType(typeof(List<DateTime>))]
    public IMultipleResults FunkyStoredProcedure(int appId, int sId, int cId)
    {
        IExecuteResult result = this.ExecuteMethodCall(this, (MethodInfo)(MethodInfo.GetCurrentMethod()), appId, sId, cId);
        return (IMultipleResults)result.ReturnValue;

    }
}

Using SQL Server Profiler, Linq 2 Sql is producing code that looks like this:

declare @p6 int
set @p6=0
exec sp_executesql N'EXEC @RETURN_VALUE = [FunkyStoredProcedure] @appId = @p0, @sId = @p1, @cId = @p2',N'@p0 int,@p1 int,@p2 int,@RETURN_VALUE int output',@p0=2,@p1=4,@p2=2,@RETURN_VALUE=@p6 output
select @p6

Which produces a result set that looks like this:

cId
-----------
694
42
43
41
4732


-----------
0

(1 row(s) affected)

Note that there are two result sets here (there should be only one.) And note that the second result set, the one that is being returned to LinqToSql is 0!

The line “exec sp_executesql…” produces the first, correct, result set.

The line “select @p6” produces the second, incorrect, result set.

First of all, why is @p6 being defined as an int? In the function I have two possible ResultTypes : List and List This seems like an issue right here.

Second, why is it not returning the output of the stored procedure? And instead returning the value of @p6?

Finally, most important, how do I get this to work correctly?

  • 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-25T18:36:00+00:00Added an answer on May 25, 2026 at 6:36 pm

    Ignore the profiler – it is leading you down the wrong path 😉

    How are you reading the results?
    You should be reading them into an IMultipleResults, and then calling GetResult<> to get the actual data
    ie.

    IMultipleResults result = dc.FunkyStoredProcedure(1,2,3);
    var ints = result.GetResult<int>();
    

    or

    IMultipleResults result = dc.FunkyStoredProcedure(1,2,3);
    var dts = result.GetResult<DateTime>();
    

    If you choose the wrong type and enumerate through the results, you will throw a SystemException (message = “Specified cast is not valid.”), so if you do not know the type, assume the one that is most likely, and if that throws the above, try the other type instead.

    Something like:

    IMultipleResults result = dc.FunkyStoredProcedure(1,2,3);
    try
    {
        var ints = result.GetResult<int>();
        DoStuffWithIntegerResults(ints);
    }
    catch(SystemException)
    {
        var dates = result.GetResult<DateTime>();
        DoStuffWithDateResults(dates);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a stored procedure that returns multiple tables. How can I execute and
I have stored procedure that returns results sorted dynamically. The parent folder (this is
I have a stored procedure that returns around 1000 rows. I want to SELECT
I have a strange, sporadic issue. I have stored procedure that returns back 5
I have a stored procedure that returns values from a temp table. In my
I have a stored procedure that returns two int Values. The first can not
I have a stored procedure that has a bunch of input and output parameters
Say I have a stored procedure that returns data from a SELECT query. I
I have a stored procedure that consists of a single select query used to
I have a stored procedure that looks like: CREATE PROCEDURE dbo.usp_TestFilter @AdditionalFilter BIT =

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.