Web design and hosting, database, cloud and social media solutions that deliver real business results
  • Business Solutions
    • Robotic Process Automation
    • Bespoke Software
    • Database Services
      • Data Integration
      • Datawarehouse Services
      • Power BI
    • Web Services
      • Logo Design
      • Payment Gateways
      • Web Site Optimisation
      • Web Site Security
      • Technical Tools
    • Cloud Services
      • Amazon Web Services
      • Google Cloud Services
      • Microsoft Azure
    • Microsoft Office
    • Social Media Services
  • Academy
    • Our Test Environment
    • Learning Databases
      • The Basics
      • Get Open Query
      • SQL Server Data
      • SQL Server Maintenance
      • Using SQL Server Dates
      • Using SQL Server Functions
      • Using SQL Server Pivot-Unpivot
      • Technical Tools
    • Learning Web Design
      • Building Ousia Content Management System
      • Using ASP-NET
      • Using CSS
      • Using JavaScript
    • Learning Cloud and IT Services
      • Task Scheduler Error 2147943645
      • Requesting SSL and Generation of PFX file in OpenSSL Simple Steps
    • Using Social Media
      • Asking for a Google Review
      • Changing a Facebook account from personal to business
      • Choosing where to focus Social Media effort
      • Social Media Image Sizes
      • Using Meta Data to set Social Media Images
  • About
    • Blog
      • Building an entry level gaming machine
      • Google Core Update Jan 2020
      • Hot Chilli Internet Closure
      • How To Choose Content For Your Website Adverts Leaflets
      • Preventing Online Scam
      • Skimmers of the gig economy
      • The most annoying things about websites on the Internet
      • Top 5 websites for free Vector Graphics
    • Portfolio
    • Team
      • Adrian Anandan
      • Ali Al Amine
      • Ayse Hur
      • Chester Copperpot
      • Fernando Ancona Camara
      • Gavin Clayton
      • Sai Gangu
      • Suneel Kumar
      • Surya Mukkamala
      • Trevor Momanyi
CS - češtinaDE - DeutschES - EspañolFR - FrançaisHI - हिंदीIT - italianoPL - polskiPT - PortuguêsRU - русскийTR - TürkZH - 中国的

Stored Procedure with Multiple Data Sets to Web Page

Stored Procedure with Multiple Data Sets to Gridviews in Web Page

Introduction

There used to be instances where I had written into my code a whole host of different SQL Commands and then treated each one individually. 

This isn't the most efficient way of accomplishing this, as in SQL you can return multiple datasets in one command, I should have looked into this a little earlier as it would have cut down the amount of code I have written in a few places in previous web pages.

So this is it at it's most simple, a stored procedure below to return 3 data sets, and then a page load event to utilise it.

Put this simple code below into one of your databases, you will need to create a simple stored proc.

SQL

ALTER PROC GetData

AS BEGIN

SELECT 1 Data UNION

SELECT 2


SELECT 3 Data2 UNION

SELECT 4


SELECT 'x' Data2 --WHERE 1<>1

END

Create gridviews

Now drag three Gridviews into your webpage or use the code below.

HTML

<asp:GridViewID="GridView1"runat="server">

asp:GridView>

<asp:GridViewID="GridView2"runat="server">

asp:GridView>

<asp:GridViewID="GridView3"runat="server">

asp:GridView>

Page Load

Next on page load, bind your data to these views, if you are copying and pasting please don't copy the class name. DataConnections is a shared class within the site I used for this.

VB

Imports DataConnections

Imports System.Data.SqlClient

Imports System.Data

Partial Class Default13

Dim con As New SqlConnection(GC)

Private Sub Page_Load() Handles Me.Load

   con.open()

   Using com As New SqlCommand("EXEC GetData", con)

   Dim da As New SqlDataAdapter(com)

   Dim ds As New DataSet

   da.Fill(ds)

   GridView1.DataSource = ds.Tables(0)

   GridView2.DataSource = ds.Tables(1)

   GridView3.DataSource = ds.Tables(2)

   GridView1.DataBind()

   GridView2.DataBind()

   GridView3.DataBind()

   End Using

End Sub

End Class

Wrapping up

You can obviously use more advanced code than this with your data sets, but the sky is the limit.

Author

Gavin Clayton
Gavin Clayton
I formed Claytabase in 2010 as a way of carrying on my work with SQL Server and ASP.NET. This has culminated in the Ousia Content Management System being taken from concept to one of the quickest CMS's on the market.

Was this helpful?

Please note, this commenting system is still in final testing.

Website design by Claytabase

This is a section of code that has been modified from Ousia Content Management System code, one of the quickest and most optimised systems on the market, part of our website design services.

These are available with sites starting at around £500.

more: Responsive and fast. Web Development, Design and Hosting with Content Management System
Copyright Claytabase Ltd 2021, registered in England and Wales 08985867

Site Links

RSS Login ContactCookie PolicySitemap

Social Media

facebook.com/Claytabaseinstagram.com/claytabase/twitter.com/Claytabaselinkedin.com/company/claytabase-ltd

Get in Touch

+442392064871info@claytabase.co.ukGround Floor, Building 1000, Lakeside North Harbour, Western Road, Portsmouth, Hampshire, United Kingdom, PO6 3EZ

Partnered With

Partners
The settings on this site are set to allow all cookies. These can be changed on our Cookie Policy & Settings page.
By continuing to use this site you agree to the use of cookies.
Ousia Logo
Ousia CMS Loader