Data Access: Using Stored Procedures
This application demonstrates how to programmatically create and use stored
procedures with ADO .NET and Microsoft SQL Server. The use of a query
(a.k.a., stored procedure) in a Microsoft Access database is also demonstrated.
Featured Highlights
-
Programmatically create stored procedures in the SQL Server database
"Northwind" by executing ad hoc SQL statements using classes from the
System.Data.SqlClient namespace.
-
Execute an existing Northwind stored procedure that does not require any
parameters, using a SqlDataReader object.
-
Execute a stored procedure that requires an input parameter and fill a
DataGrid with the results.
-
Execute a stored procedure that requires both input and output parameters, and
that makes use of a return value.
-
Execute an existing query (stored procedure) in the Microsoft Access
version of Northwind using classes in the System.Data.OleDb namespace. (The
Northwind database is included with this How To.)
Requirements
This application requires the release version of Visual Studio .NET Professional
(or greater) and access to the Northwind database residing in SQL Server or the
Microsoft Data Engine (MSDE). To install MSDE, do the following:
1. Open the Start menu, click Programs, click Microsoft .NET
Framework SDK, and then click Samples and Quickstart Tutorials.
2. Click "Step 1: Install the .NET Framework Samples Database".
3. Open a command window, and CD to
\Samples\Setup This is typically : C:\Program Files\Microsoft
Visual Studio .NET\FrameworkSDK\Samples\Setup
4. Type: osql -E -S (local)\NetSDK -i InstNwnd.sql
Running the Sample
Simply press F5.
Other links:
HOW TO:
Call a Parameterized Stored Procedure by Using ADO.NET and Visual Basic .NET
(Q308049)
PRB:
Output Parameters Are Not Returned When You Run an ADO.NET Command in Visual
Basic .NET (Q308051)