Professional Documents
Culture Documents
Home
Categories
ASP.Net
C#.Net
JavaScript
ADO.Net
Excel
AJAX
VB.Net
SQL Server
GridView
Silverlight
JQuery
DataList
Snippets
XML
New Features
.Net 4.0
http://www.aspsnippets.com/Articles/Select-SQL-Server-Stored-Procedures-using-ASPNet-Example.aspx 1/18
28/10/2014 Select SQL Server Stored Procedures using ASP.Net Example | ASP.Net, C#.Net, VB.Net, AJAX,JQuery, JavaScript, GridView,SQL Server, RDLC, S…
TreeView
jQuery Plugins
ASP.Net Validators
WCF
Repeater
Regular Expressions
Yahoo API
iTextSharp
Charts
ListView
Tweeter
CSS
SMS
DotNetZip
Crystal Reports
Entity Framework
HyperLink
RDLC Report
SqlDataSource
Menu
http://www.aspsnippets.com/Articles/Select-SQL-Server-Stored-Procedures-using-ASPNet-Example.aspx 2/18
28/10/2014 Select SQL Server Stored Procedures using ASP.Net Example | ASP.Net, C#.Net, VB.Net, AJAX,JQuery, JavaScript, GridView,SQL Server, RDLC, S…
YouTube
HTML
XmlDataSource
ListBox
Tips
DataGridView
Cryptography
Windows Forms
WebUserControl
RSS Feeds
HTML5
Sitemap
IIS
LINQ
DataPager
URL Routing
SqlBulkCopy
OCR
ASP.Net 4.5
Master Pages
MySQL
CSV
http://www.aspsnippets.com/Articles/Select-SQL-Server-Stored-Procedures-using-ASPNet-Example.aspx 3/18
28/10/2014 Select SQL Server Stored Procedures using ASP.Net Example | ASP.Net, C#.Net, VB.Net, AJAX,JQuery, JavaScript, GridView,SQL Server, RDLC, S…
Forums
Contact
Search
Eg. Send Email ASP.Net
Home
Categories
Forums
Contact
Search
Eg. Send Email ASP.Net
Here Mudassar Ahmed Khan has explained how to call Select SQL Server Stored Procedures
using ADO.Net in as ASP.Net Web Application and also how to bind the data returned by the
stored procedures to ASP.Net GridView.
Download
http://www.aspsnippets.com/Articles/Select-SQL-Server-Stored-Procedures-using-ASPNet-Example.aspx 4/18
28/10/2014 Select SQL Server Stored Procedures using ASP.Net Example | ASP.Net, C#.Net, VB.Net, AJAX,JQuery, JavaScript, GridView,SQL Server, RDLC, S…
ASPSnippets
Like
ASPSnippets
Here I amFollow
explaining how to create and call stored procedures in .net using ADO.Net classes.
In my previous article I explained Using Stored Procedures in SQL Server Database
Here I am explaining how to call stored procedures that return data using ADO.Net. I’ll also
explain how to bind the results to databound controls like GridView or DataGrid.
336 have us in circles
For this tutorial I am using the Employees Table of NorthWind Database. You can download the
NorthWind Database from here
ASP on Twitter
Follow
Connection String
ASP has 223 Followers
<connectionStrings>
<add name="conString"
connectionString="Data
Jose G. Alvarez
Tim
R. Mugodo
Juanchi Sopan MaitiSource=.\SQLEXPRESS;
Kalpesh Bhadra Katrina 坂爪 美夏 Juan Guillermo
Helio
A. Pereira Brian Downey
database=Northwind;Integrated Security=true"/>
connectionStrings>
Namespaces
http://www.aspsnippets.com/Articles/Select-SQL-Server-Stored-Procedures-using-ASPNet-Example.aspx 5/18
28/10/2014 Select SQL Server Stored Procedures using ASP.Net Example | ASP.Net, C#.Net, VB.Net, AJAX,JQuery, JavaScript, GridView,SQL Server, RDLC, S…
C#
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
VB.Net
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[GetAllEmployeeDetails]
AS
BEGIN
SET NOCOUNT ON;
SELECT FirstName, LastName, BirthDate, City, Country
FROM Employees
END
Now I’ll call the stored procedure using ADO.Net in my ASP.Net website and bind the results to
a GridView. Since I need to fetch multiple rows I’ll be using ExecuteReader method of SQL
Command object
C#
http://www.aspsnippets.com/Articles/Select-SQL-Server-Stored-Procedures-using-ASPNet-Example.aspx 6/18
28/10/2014 Select SQL Server Stored Procedures using ASP.Net Example | ASP.Net, C#.Net, VB.Net, AJAX,JQuery, JavaScript, GridView,SQL Server, RDLC, S…
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "GetAllEmployeeDetails";
cmd.Connection = con;
try
{
con.Open();
GridView1.EmptyDataText = "No Records Found";
GridView1.DataSource = cmd.ExecuteReader() ;
GridView1.DataBind();
}
catch (Exception ex)
{
throw ex;
}
finally
{
con.Close();
con.Dispose();
}
VB.Net
http://www.aspsnippets.com/Articles/Select-SQL-Server-Stored-Procedures-using-ASPNet-Example.aspx 7/18
28/10/2014 Select SQL Server Stored Procedures using ASP.Net Example | ASP.Net, C#.Net, VB.Net, AJAX,JQuery, JavaScript, GridView,SQL Server, RDLC, S…
Finally
con.Close()
con.Dispose()
End Try
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[GetEmployeeDetailsByID]
@EmployeeID int = 0
AS
BEGIN
SET NOCOUNT ON;
SELECT FirstName, LastName, BirthDate, City, Country
FROM Employees WHERE EmployeeID=@EmployeeID
END
Now in order to call the above stored procedure in an asp.net application using ADO.Net we will
have to do it the following way. You will notice all remains the same except here I am passing
@EmployeeID as parameter. Also you will notice txtID which is a TextBox in which user enters
the EmployeeID of the Employee whose details he wants to view
C#
http://www.aspsnippets.com/Articles/Select-SQL-Server-Stored-Procedures-using-ASPNet-Example.aspx 8/18
28/10/2014 Select SQL Server Stored Procedures using ASP.Net Example | ASP.Net, C#.Net, VB.Net, AJAX,JQuery, JavaScript, GridView,SQL Server, RDLC, S…
cmd.Connection = con;
try
{
con.Open();
GridView1.EmptyDataText = "No Records Found";
GridView1.DataSource = cmd.ExecuteReader();
GridView1.DataBind();
}
catch (Exception ex)
{
throw ex;
}
finally
{
con.Close();
con.Dispose();
}
VB.Net
http://www.aspsnippets.com/Articles/Select-SQL-Server-Stored-Procedures-using-ASPNet-Example.aspx 9/18
28/10/2014 Select SQL Server Stored Procedures using ASP.Net Example | ASP.Net, C#.Net, VB.Net, AJAX,JQuery, JavaScript, GridView,SQL Server, RDLC, S…
Throw ex
Finally
con.Close()
con.Dispose()
End Try
This completes the article in my next article I’ll be explaining how to call insert stored procedures
in asp.net using ADO.Net. You can download the code in VB.Net and C# along with the SQL
Scripts using the link below
Download
Part - II Calling Insert SQL Server Stored Procedures using ADO.Net >>
http://www.aspsnippets.com/Articles/Select-SQL-Server-Stored-Procedures-using-ASPNet-Example.aspx 10/18
28/10/2014 Select SQL Server Stored Procedures using ASP.Net Example | ASP.Net, C#.Net, VB.Net, AJAX,JQuery, JavaScript, GridView,SQL Server, RDLC, S…
http://www.aspsnippets.com/Articles/Select-SQL-Server-Stored-Procedures-using-ASPNet-Example.aspx 11/18
28/10/2014 Select SQL Server Stored Procedures using ASP.Net Example | ASP.Net, C#.Net, VB.Net, AJAX,JQuery, JavaScript, GridView,SQL Server, RDLC, S…
Related Articles
http://www.aspsnippets.com/Articles/Select-SQL-Server-Stored-Procedures-using-ASPNet-Example.aspx 12/18
28/10/2014 Select SQL Server Stored Procedures using ASP.Net Example | ASP.Net, C#.Net, VB.Net, AJAX,JQuery, JavaScript, GridView,SQL Server, RDLC, S…
Comments
best...
More
http://www.aspsnippets.com/Articles/Select-SQL-Server-Stored-Procedures-using-ASPNet-Example.aspx 13/18
28/10/2014 Select SQL Server Stored Procedures using ASP.Net Example | ASP.Net, C#.Net, VB.Net, AJAX,JQuery, JavaScript, GridView,SQL Server, RDLC, S…
Add Comments
You can add your comment about this article using the form below. Make sure you provide a
valid email address
else you won't be notified when the author replies to your comment
Please note that all comments are moderated and will be deleted if they are
http://www.aspsnippets.com/Articles/Select-SQL-Server-Stored-Procedures-using-ASPNet-Example.aspx 14/18
28/10/2014 Select SQL Server Stored Procedures using ASP.Net Example | ASP.Net, C#.Net, VB.Net, AJAX,JQuery, JavaScript, GridView,SQL Server, RDLC, S…
Name
Name
Email
Email
Comment
Comment
Security code:
Add Comment
Javid
Information provided by you is beneficial for the students as well as for the developers.
Anidesh Madhav
All your example are very helpful. Simple and easy to understand as well.
Vishant
Your code is very helpful and usable..
Thank you for giving help for code and wish to always help us like this.
Vishant
Mary Ticong
It’s really fantastic Thanks
Keep on making this amazing tutorial It’s a great help for us beginners...
Katheeja
This site is like Google for asp.net developers. Simple and worthy..
Dhruv
Nice work ASP Snippets team... Keep it up.
Your methods of explanation are in simple language even non IT person can understand quickly...
Karthik
I have been using many of your posts for reference and it’s very easy... Keep doing this wonderful
work...
JK
This is the most useful .Net site I’ve found - I love it. Thank you for sharing all these tips and tricks.
Umesh
This is very nice and informative website for students, freshers as well as for employee also.
Thanks.
Raju Raval
http://www.aspsnippets.com/Articles/Select-SQL-Server-Stored-Procedures-using-ASPNet-Example.aspx 15/18
28/10/2014 Select SQL Server Stored Procedures using ASP.Net Example | ASP.Net, C#.Net, VB.Net, AJAX,JQuery, JavaScript, GridView,SQL Server, RDLC, S…
Respected sir your articles are awesome. I use this SMS sending trick in my asp.net application in
my study. Thank you. I regularly visit your articles... Please keep it up.
Iron
You are number one. Thanks.
EC
Great website great articles! This is a good site for both newbies and experience developers. It
helps me achieve dome very changing tasks in a short period of time.
Juan Elizalde
I just want to say thank you, I am an active visitor of your site and it is really useful, I work as a
Software Consultant in Mexico.
Congratulations because you help people and the world to change using technology.
Suraj Petkar
Nice ...It really helped....Very good site. Lots of helpful stuff on it.
Thanks.
Petros
The simple ones are the best just plug in a few lines of code and it does the job complete as well
demo and source available
Syed Jalal Tashrrifullahi
The sheer brilliance of Mudassar inspires me. Another great article showing how simplicity is can
be REALLY effective.
vikram parmr
This is the superb site ever found so cool. It’s an amazing thing has been started by khan sir salute
to you.
Lita Pierce
Golden piece of code I appreciate that you have taken a bit of time pulling this together and I just
wanted to say THANK YOU MAN. Good work and keep posting.
Edson Cruz
Thank you Mr. Khan. Your articles have been helped a lot.
That’s it.
Doug
Just want to thank you very much for this article. I have spent hours searching for a solution to a
very similar page I am building and I was giving up hope on getting it to work.
Thanks to this page and this site.
Noorulla Khan
Mudassar bhai you rock man really working fine. May Allah Almighty fulfill your most halal desires.
Ameen.
Mahmoud
I would like to thank you for this site. It is good site for learning.
Shatrughan Singh Kshatri
You are always being honest about your work.
Shoni
Since i started using this site i have gained a lot of experience in C and VB.net as i am currently
working on both of them.
This is the best and the explanation is clear. Keep the good work.
Thumbs Up.
Mayank Pathak
Awesome Mudassar ...
I am already a follower of your posts on forums.asp.net....
Nice example mate...It works superb.
Rupesh
Thanks a lot your articles are very nice. It will help the learners a lot.
Ameer Abulawi
This is Great. This website Rocks.
Thank you Mudassar
Emmanuel
I have read many of your post and they have helped me alot. Thanks Khan.
Asif Aziz
http://www.aspsnippets.com/Articles/Select-SQL-Server-Stored-Procedures-using-ASPNet-Example.aspx 16/18
28/10/2014 Select SQL Server Stored Procedures using ASP.Net Example | ASP.Net, C#.Net, VB.Net, AJAX,JQuery, JavaScript, GridView,SQL Server, RDLC, S…
Very nice explanation of Ajax. This was first time I was learning Ajax. I was explained so nicely that
I understand each step in glance
Nabil Elibairy
Very good detailed step by step with explanation of every how and why. We appreciate your
sincere willing to teach.
Mohammad
Appreciated. Thank you very much. You are a great developer.
Javed Ahmad
I have always visited many times your site and always find Something new for Self as Software
Engineer your site is very very useful for Dot Net Platforms user Allah mercy have on you always.
Anonymous
I have to admit it you are great. I found solutions to my ASP.NET problems two times during the
last 2 days.
Thank you very much.
Alexis
Wow. Thank’s your articles are very GOOD!!!
Jagdish
Please add articles like this.
Your all articles are very useful covers most of …
THANK YOU.
Mayur Nagavadiya
Thank you sir.
After visiting your blog now i understand the concept of procedure it is very good for fresher.
Once again Thanks a lot......
Willfred
You are simply awesome Mudassar Khan.....
Thank you very very much :)
Furqan
Amazing website, Great articles, To the point content.
Keep up the good work.
Ariba Ahmed
Its best guidance for me and for my husband...
kashif
Mudassar Allah aap ko duniya aur aakhrat mae bohat bohat ajar dae Ameen,
Aur meri dua a k Allah ji aap ko jannat mae ek khobsorat baag b daen, Bagh-e-Kashaf k naam sa
:) Thank you so much your blog has helped me so many times.
Abhijit
You are Legend my friend.
Sameer Idris
I have to admit it you are great. I found solutions to my ASP.NET problems two times during the
last 2 days.
Thank you very much.
Nick
Nice guide.
The only working guide to do this I have found (that doesn't use MVC).
FLEITES
Maestro-Teacher Thank you very much for your tutorials!
Dmitry
Man I am really very grateful to you The only short and 100 functioning example in the web.
Vijay
Dear Friend Mudassar
I really want to thank to you cause you are not only helping us by your posts you also helping us to
feed our parents.
Thanks and God Bless
Khwaja Mohammad Sayem
Thank you very much for your "Enlarge Image View in ASP.Net GridView". Two days I have spent
for this solution.
http://www.aspsnippets.com/Articles/Select-SQL-Server-Stored-Procedures-using-ASPNet-Example.aspx 17/18
28/10/2014 Select SQL Server Stored Procedures using ASP.Net Example | ASP.Net, C#.Net, VB.Net, AJAX,JQuery, JavaScript, GridView,SQL Server, RDLC, S…
Subscribe
Subscribe
Solutions
http://www.aspsnippets.com/Articles/Select-SQL-Server-Stored-Procedures-using-ASPNet-Example.aspx 18/18