Net-informations.com
SiteMap  | About    

GridView from Stored Procedure



In this article, you can see how to populate a gridview from stored procedure.

Stored Procedure

A stored procedure is a group of Transact-SQL statements compiled into a single execution plan. Stored procedures are more secure than SQL queries code and often get result faster.

Database

In this article I have used Microsoft's Pubs database for sample data. You can download it free from the following link.

Download

How to create a Stored Procedure ?

The following SQL statements will create a Store Procedure.

gridview from stored procedure

The above code create a store procedure named as 'SPPUBLISHER' and it execute SQL statement that select data of all publishers from publishers table from the PUB database.

Grid View Binding using Stored Procedure

You can retrieve data from database using this Store Procedure and display it in a GridView.

To call a stored procedure from C# application, set the CommandType of the Command object to StoredProcedure.

Next step is to inform the your Store Procedure name to the Command Object.

The rest of the things are same as SQl Query string.

gridview populate from stored procedure

Finally you can set GridView DataSource as your Dataset.

bind gridview

Default.aspx

C# Source Code

VB.Net Source Code








net-informations.com (C) 2019    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.