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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:06:52+00:00 2026-06-11T23:06:52+00:00

I have an SP which returns an unknown amount of data, here is an

  • 0

I have an SP which returns an unknown amount of data, here is an example for my query:

MySP:

WHILE (@counter <= @SomeParameter)
BEGIN
   Select *
   From tblFoo
   Where tblFoo.Counter=@counter

   @counter=@counter+1
END

In order to store the data efficiently I would like to use DataSet , that will store in each of it’s DataTable the result for each of the Selects.

Since my application is based on EF 5 , I tried to call my SP with my dbContext object, here is what I tried to do.

var ds=db.Database.SqlQuery<DataSet>("MySP @counter @SomeParameter", value1,value2);

That doesn’t seem to work properly.

I thought of using the classic ADO.NET to solve this matter, and use SqlDataAdapter , But I am not sure how to pass the original Connection reference from the dbContext to the SqlDataAdapter.Connection Property since its not the same type.

Note: The reason I am using DataSet and not Entities Collection at this matter is because the results I am getting from the SP could have different columns and therefore I’m not sure if Entities Collection will do.

I would like to know how to call my SP using Entities (or SqlAdapter) to fill each of the tables at my DataSet with the results of each Select from my SP.

I’m fresh at EF so if I am thinking or doing anything wrong any tip would be appriciated.

  • 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-06-11T23:06:54+00:00Added an answer on June 11, 2026 at 11:06 pm

    You can try with this code – based on SqlDataAdapter class

    var connectionString = "...";
    using (SqlConnection connection = 
            new SqlConnection(connectionString))
        {
            SqlDataAdapter adapter = new SqlDataAdapter();
    
             var cmd = new SqlCommand("YourSP", connection);//Adjust your stored procedure name
             cmd.CommandType = CommandType.StoredProcedure;
             cmd.Parameters.Add(new SqlParameter("@SomeParameter", YourValue));//Adjust your value
    
             adapter.SelectCommand = cmd;
             adapter.Fill(dataset);
            return dataset;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a query which returns two rows of data as count. I want
I have a query which returns a series of cells of data from a
Hi guys i have controller which returns a partial view, the controller is called
In my application I have methods which returns a control (checkbox, radiobutton, textbox) but
I have a method which returns single word as a String. I need to
I have a Controller which returns a ViewModel to a View and it works
I have a function which returns a one-sided intersection of values between two input
I have a method which returns some xml in a memory stream private MemoryStream
I have a script which returns a price for a product. However, the price
I have a method which returns an array of fixed type objects (let's say

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.