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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:13:02+00:00 2026-05-31T14:13:02+00:00

My SQL stored procedure is as follows: CREATE PROCEDURE [dbo].[GetTradeByLevel]( @LevelId INT ) AS

  • 0

My SQL stored procedure is as follows:

CREATE  PROCEDURE [dbo].[GetTradeByLevel](
@LevelId INT                  
)
AS
BEGIN
if(@LevelId=1)
BEGIN
select * from CHANNELCLASS 
select a.* from accountmaster a join CHANNELCLASS b on        a.ChannelClassificationId=b.ChannelClassificationId 
select r.* from REGION r join accountmaster a on r.Accountid=a.AccountID 
select s.* from STORE s join REGION r on s.RegionID=r.RegionId
END
else if(@LevelId=2)
BEGIN
select a.* from accountmaster a join CHANNELCLASS b on  a.ChannelClassificationId=b.ChannelClassificationId
select r.* from REGION r join accountmaster a on r.Accountid=a.AccountID
select s.* from STORE s join REGION r on s.RegionID=r.RegionId
END
else if(@LevelId=3)
BEGIN
select r.* from REGION r join accountmaster a on r.Accountid=a.AccountID
select s.* from STORE s join REGION r on s.RegionID=r.RegionId
END
else if(@LevelId=4)
BEGIN
select s.* from STORE s join REGION r on s.RegionID=r.RegionId
END
END

GO

I have to call this stored procedure in C# console application. If my parameter value is 1 it means I have to store 4 table values in a C# List<>. I have tried, but it stores only the first table’s data.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace ConsoleApplication3
{
class Program
{
    static void Main(string[] args)
    {
        int v = 1;
        int cl;
        SqlConnection con = new SqlConnection("Data Source=CTSINDLFVMOSS;Initial Catalog=DB_CGTPO_DEVE;User ID=DB_CGTPO_DEVE;Password=cgtpo");
        con.Open();
        SqlCommand cmd = new SqlCommand("GetTradeByLevel", con);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@LevelId", v);
        List<string> customers = new List<string>();
        using (SqlDataReader dr = cmd.ExecuteReader())
        {
            cl = dr.FieldCount;
            while (dr.Read())
            {
                for (int i = 0; i < cl; i++)
                {
                    customers.Add(dr[i].ToString());
                    //customers.Add(dr[1].ToString());
                    //customers.Add(dr[2].ToString());
                }
            }
        }
        for (int i = 0; i < customers.Count; i++) // Loop through List with for
        {
            Console.WriteLine(customers[i]);
        }
        con.Close();
    }
    }
}

This is my console application page… if my parameter value is 1 mean it have to store 4 table values but it will taking first table value only i have to store all 4 table values
any one help me,….

  • 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-31T14:13:03+00:00Added an answer on May 31, 2026 at 2:13 pm

    yupes NextResult()

    example:

    dim dr as sqldatareader = <your command that will return data>
    
    while dr.read
    'do stuff
    end while
    
    dr.NextResult()
    
    while dr.read...
    

    if you perform multiple selects in your stored procedure, all will be contained in the SqlDataReader, it’s just your method of advancing the reader…

    http://www.mindfiresolutions.com/NextResult-in-C-or-ADONET-data-reader-705.php

    • 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 as follows create procedure [dbo].[PriceConfirm] @quote float, @membershipType int,
Stored procedure is as follows: CREATE PROCEDURE Foo @bar varchar(100) AS SELECT * FROM
I have a T-SQL stored procedure with the signature CREATE PROCEDURE MyProc @recordCount INT
Suppose I have a PL/SQL stored procedure as follows: PROCEDURE do_something(foo VARCHAR2 DEFAULT NULL)
I have two PL/SQL Stored procedure each handling its own Transaction (Begin/Commit and Rollback
I am creating a simple stored procedure in VS 2010/SQL Server 2008 as follows:
i have a simple oracle stored procedure proc1 as follows: CREATE OR REPLACE PROCEDURE
Have a Sql Script file name spCreation.sql with the following contents. CREATE PROCEDURE dbo.usp_select_customers
I have this SQL Server 2008 UDT: CREATE TYPE [dbo].[IdentityType] AS TABLE( [Id] [int]
I want to create SQL statement (probably a stored procedure) to insert multiple rows

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.