Blue Theme Orange Theme Green Theme Red Theme
 
6 Months Free & No Setup Fees ASP.NET Hosting!
Home | Forums | ASP.NET 2.0 Tutorials | Web Services | How Do I...? | Class Browser | WPF Quick Starts | Advertise with Us
 | Consulting  
Submit an Article Submit a Blog 
Search :       Advanced Search »
Home » Blogs Home » Blog Detail

Calling DataSet with Stored Procedure in 3-tier

 by Krishna Garad on Jan 21, 2011

We will see how to call a DataSet with stored procedure with parameter in a 3-tier application.
Comments: 2 Views: 3364 Printable Version 
Introduction:

Here we will see how to call the DataSet method which will get the data from database with stored procedure.

In so many cases we need to call the select statement on some condition for this we have to go for stored procedure and if the project architecture is n-tier then it's very difficult. We can use Microsoft SqlHelper class also but the same thing I've done very easy manner here. Let's see step-by-step.

Data Access Layer:

In this layer we have to write the function which will acually interact with our database. This function is Dataset function and will return Dataset object.

public static DataSet GetData(string _sql, SqlParameter[] Param)
    {
        try
        {
            sqlcmd = new SqlCommand(_sql, sqlcn);
            // cdm.CommandText = _sql;
            foreach (SqlParameter p in Param)
            {
                sqlcmd.Parameters.Add(p);

            }
            sqlcmd.CommandType = CommandType.StoredProcedure;
            sqlcn.Open();
            DataSet ds = new DataSet();
            sqlda = new SqlDataAdapter(sqlcmd);
            sqlda.Fill(ds);
            return ds;

        }
        catch (Exception)
        {

            throw;
        }
        finally
        {
            sqlcn.Close();
        }

    }


Business Logic Layer:

Here we have to write again Dataset function which will pass the stored procedure name and List of parameter required and receive the result Dataset from Data Access Layer in Dataset.

public DataSet GetData("Parameter list if necessary")
    {
        string _sql = "SpName";
//List of parameter required
        SqlParameter[] Param = new SqlParameter[0];
        DataSet ds = DataHelper.GetData(_sql,param);
        return ds;
    }

User Interface:

Here again we have to recieve the dataset return by our Business Logic Class.

Dataset ds=ClassObj.GetData("values")

bind this ds or use ds as you want now.


Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.
 
What do you say about this post? Post a comment here
*Title:
*Comment:
 

Thank's by Krishna Garad On Jan 21, 2011
Thank's Maheshji. Next time I'll take care.

Feedback by Mahesh Chand On Jan 21, 2011
Krishna, Please check this feedback in future. 1. I moved blog to ADO.NET & Database section. It belongs to ADO.NET. 2. Fixed spelling and grammar. Use Microsoft Word to type and keep Spell Checker on so it will tell you spelling mistates. Keep up the good work! Cheers!

6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor

 Blogger's Profile
Age: 25
Location:
Title: Developer
Joined: Dec 22, 2010
Education: Masters Degree
 More Blogs from this Blogger
No record available
 Latest Blogs
[Video] OnClose Handler
[Video] Storing and Loading the Window and Toolbar position
The Euclidean Algorithm
Swapping Exe Process
How Exe file is Generated by VS2005 C++ Project?
What is Exe
Header files: Multiple Inclusion problem - Solution B
Header files: Multiple Inclusion problem - Solution A
Header files: Multiple Inclusion problem - Reason
Header files: Multiple Inclusion problem
View all »
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 
Team Foundation Server Hosting
 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.