How to handle a stored procedure that returns variable number of fields

Posted on 2005-05-10
Last Modified: 2010-04-16
Hi experts,

We need to handle in a report (data grid or html table) that shows the result from a stored procedure that returns a variable number of fields, it's about a statistics report (crosstab), so depending the pivot column the user selects the sp will return a diferent number of fields:

by city:

product, city1, city2, city3
product A, $100.00, $500.00, $400.00
product B, $3200.00, $4500.00, $4400.00

by year:

product, 2001, 2002, 2003, 2004, 2005
product A, $100.00, $500.00, $400.00, $4500.00, $1400.00
product B, $3200.00, $4500.00, $4400.00, $2500.00, $2400.00

we won't be able to predict the number of fields, it will depend on the data,

we need some idea how to handle this in a efficent way...

Thanks in advance

Carlos V.
    LVL 2

    Accepted Solution


    you can do that easily with a data Adapter (available for most databases)

    then you fill a DataSet with the returned value of the Stored Procedure.

    if you bind it to a DataGrid an choose "AutoGenerateColumns" the component will handel that itself how many columns to generate

    hope that solves your problem

    cu WebSpecials

    Author Comment

    thanks webspecials, it's the right way...

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    In one of my recent projects, I was working with IP cameras, I need to take some pictures from the camera and do some processing on it. The first step, was to retrieve the image from camera into Image object. So that it can be displayed or …
    Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    This video discusses moving either the default database or any database to a new volume.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now