MS SQL Server
  Home arrow MS SQL Server arrow Page 4 - Pulling Information using DataAdapter with...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Moblin 
JMSL Numerical Library 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
MS SQL SERVER

Pulling Information using DataAdapter with ADO.NET
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 13
    2006-05-02

    Table of Contents:
  • Pulling Information using DataAdapter with ADO.NET
  • How to retrieve several rows returned by a stored procedure using "DataAdapter" in ADO.NET from ASP.NET
  • How to retrieve only one row returned by a stored procedure using "DataAdapter" in ADO.NET from ASP.NET
  • How to retrieve multiple result sets from stored procedure using "DataAdapter" in ADO.NET from ASP.NET

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Pulling Information using DataAdapter with ADO.NET - How to retrieve multiple result sets from stored procedure using "DataAdapter" in ADO.NET from ASP.NET


    (Page 4 of 4 )

    Now, we shall examine an interesting issue -- multiple result sets.  Before talking about multiple result sets, let us look at the following stored procedure:

    CREATE PROCEDURE dbo.sp_getAll
    AS
          SELECT * FROM dept
          SELECT * FROM emp
    RETURN

    The above stored procedure is very simple to understand.  It simply returns two "sets" of data.  The first set is all rows from the table "dept" and the other one is all rows from the table "emp."  Since the stored procedure is trying to give back (or return) more than one set (or table) of information, we call it a stored procedure returning multiple result sets.

    How about retrieving multiple result sets in .NET?  We have two methods for doing this. And now I start with DataAdapter in this section.

    The steps will be very similar to the ones I specified in the previous sections.  I shall work directly with the code now.  Add a new web form (call it  "SPMultipleResultSets") with a single button captioned "Retrieve Multiple resultsets" and two data grids (simply "datagrid1" and "datagrid2").

    After designing the form, switch to the code and add the following line at the top.

    Imports System.Data.SqlClient

    Add the following code to your "Retrieve Multiple resultsets" button:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
    As System.EventArgs) Handles Button1.Click
            Dim name As String
            Dim cn As New SqlConnection("Data Source=.;initial
    catalog=Northwind;user id=sa")
            Dim cmd As New SqlCommand
            With cmd
                .CommandType = CommandType.StoredProcedure
                .CommandText = "sp_getAll"
                .Connection = cn
            End With
            Dim ds As New DataSet
            Dim da As New SqlDataAdapter(cmd)
            da.Fill(ds)
            da.Dispose()
            cmd.Dispose()
            cn.Close()
            Me.DataGrid1.DataSource = ds.Tables(0)
            Me.DataGrid1.DataBind()
            Me.DataGrid2.DataSource = ds.Tables(1)
            Me.DataGrid2.DataBind()
            ds.Dispose()
        End Sub

    Set the start page, execute your application (by pressing F5) and click on the button "Retrieve Multiple resultsets."  Once it executes successfully, you should be able to view the list of all departments and the list of all employees in the two data grids (separately).

    Within the above code, I used "dataset" instead of "datatable."  A dataset can contain any number of datatables inside it.  And thus, we can fetch any number of multiple resultsets as well!

    I developed the application using Microsoft Windows Server 2003 Standard Edition with Microsoft Visual Studio.NET 2003 Enterprise Architect and Microsoft SQL Server 2000. If anything does not work, please drop me line so that I can guide you.  The entire solution for this article is freely available in the form of a zip downloadable. 

    Any comments, suggestions, feedback, bugs, errors, enhancements are highly appreciated at jag_chat@yahoo.com


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · Hello guys, I hope you are enjoying this series. This is another contribution for...
     

    MS SQL SERVER ARTICLES

    - Completing the Introduction to Transact-SQL
    - A Brief Introduction to Transact-SQL
    - Lookups and Blocking Bad Data
    - Field Validation Rules for Blocking Bad Data
    - Using Masks to Block Bad Data
    - Blocking Bad Data
    - Using @@ROWCOUNT and TABLE Variables for Dat...
    - How to Use Variables, IF and CASE in Databas...
    - Creating Important Aspects of Notification S...
    - Working wth Variables in Database Interactio...
    - Delving Deeper into Notification Services
    - Notification Services
    - Building a Multi-table Report with SQL 2005 ...
    - A Secure Way of Building Connection Strings
    - Transferring a Database Using the SSIS Desig...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway