|
|
|
|
|
|
|
Technologies:
.NET 1.0/1.1, ASP.NET 1.0, Web Services,Visual C# .NET
|
|
Total downloads :
|
|
|
Total page views :
|
63400
|
|
Rating :
|
|
3/5
|
|
This article has been rated :
|
3 times
|
|
|
|
Similar ArticlesMost ReadTop RatedLatest
|
|
Related EbooksTop Videos
|
|
|
Description
|
|
The Complete Visual C# Programmer's Guide, written by the authors of C# Corner, covers most of the major components that make up C# and the .NETenvironment including Windows Forms, ADO.NET, GDI+, Web Services, and Security. The book is geared toward the beginner to intermediate programmers.
|
|
|
|
|
|
|
|
|
|
|
|
|
Introduction
Stored procedures (sprocs) are generally an ordered series of Transact-SQL statements bundled into a single logical unit. They allow for variables and parameters, as well as selection and looping constructs. A key point is that sprocs are stored in the database rather than in a separate file.
Advantages over simply sending individual statements to the server include:
- Referred to using short names rather than a long string of text; therefore, less network traffiic is required to run the code within the sproc.
- Pre-optimized and precompiled, so they save an incremental amount of time with each sproc call/execution.
- Encapsulate a process for added security or to simply hide the complexity of the database.
- Can be called from other sprocs, making them reusable and reducing code size.
Parameterization
A stored procedure gives us some procedural capability, and also gives us a performance boost by using mainly two types of parameters:
- Input parameters
- Output parameters
From outside the sproc, parameters can be passed in either by position or reference.
Declaring Parameters
- The name
- The datatype
- The default value
- The direction
The syntax is :
@parameter_name [AS] datatype [= default|NULL] [VARYING] [OUTPUT|OUT]
Let's now create a stored procedure named "Submitrecord".
First open Microsoft SQL Server -> Enterprise Manager, then navigate to the database in which you want to create the stored procedure and select New Stored Procedure.

See the below Stored Procedure Properties for what to enter, then click OK.

Now create an application named Store Procedure in .net to use the above sprocs.
Stored Procedure.aspx page code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Store Procedure</title> </head> <body> <form id="form1" runat="server"> <div> <asp:Label ID="Label1" runat="server" Text="ID"></asp:Label> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br /><br /> <asp:Label ID="Label2" runat="server" Text="Password"></asp:Label> <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br /><br /> <asp:Label ID="Label3" runat="server" Text="Confirm Password"></asp:Label> <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox><br /><br /> <asp:Label ID="Label4" runat="server" Text="Email ID"></asp:Label> <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox><br /><br /><br /> <asp:Button ID="Button1" runat="server" Text="Submit Record" OnClick="Button1_Click" /> </div> </form> </body> </html>
Stored Procedure.aspx.cs page code
using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Data.SqlClient; public partial class _Default : System.Web.UI.Page { DataSet ds = new DataSet(); SqlConnection con; //Here we declare the parameter which we have to use in our application SqlCommand cmd = new SqlCommand(); SqlParameter sp1 = new SqlParameter(); SqlParameter sp2 = new SqlParameter(); SqlParameter sp3 = new SqlParameter(); SqlParameter sp4 = new SqlParameter();
protected void Page_Load(object sender, EventArgs e) { }
protected void Button1_Click(object sender, EventArgs e)
{ con = new SqlConnection("server=(local); database= gaurav;uid=sa;pwd="); cmd.Parameters.Add("@ID", SqlDbType.VarChar).Value = TextBox1.Text; cmd.Parameters.Add("@Password", SqlDbType.VarChar).Value = TextBox2.Text; cmd.Parameters.Add("@ConfirmPassword", SqlDbType.VarChar).Value = TextBox3.Text; cmd.Parameters.Add("@EmailID", SqlDbType.VarChar).Value = TextBox4.Text; cmd = new SqlCommand("submitrecord", con); cmd.CommandType = CommandType.StoredProcedure; con.Open(); cmd.ExecuteNonQuery(); con.Close(); } }
When we run the application, the window will look like this:

After clicking the submit button the data is appended to the database as seen below in the SQL Server table record:

|
|
|
Login
to add your contents and source code to this article
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional
consulting company, our consultants are well-known experts in .NET and many of them
are MVPs, authors, and trainers. We specialize in Microsoft .NET development and
utilize Agile Development and Extreme Programming practices to provide fast pace
quick turnaround results. Our software development model is a mix of Agile Development,
traditional SDLC, and Waterfall models.
|
|
Click here to learn more about C# Consulting. |
|
|
|
|
|
|
|
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon.
Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees.
As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
|
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
|
Go.NET
Build custom interactive diagrams, network, workflow editors, flowcharts, or software design tools. Includes many predefined kinds of nodes, links, and basic shapes. Supports layers, scrolling, zooming, selection, drag-and-drop, clipboard, in-place editing, tooltips, grids, printing, overview window, palette. 100% implemented in C# as a managed .NET Control. Document/View/Tool architecture with many properties&events. Optional automatic layout.
|
Dundas Software
Dundas Chart for .NET is the most advanced .NET charting package available today. With an extremely complete feature set, elegant architecture and easy implementation, Dundas Chart can quickly add advanced Charting functionality to enhance and transform ASP.NET and Windows Forms applications. Whether you are implementing charting into internal projects, or building applications for clients, Dundas Chart offers advanced technology and advanced results to get the most out of data.
|
Clickatell's SMS Gateway
Clickatell's Developer Solutions allow you to SMS enable any website or
application via a range of API's. Learn More about our API connections.
|
Microsoft Visual Studio 2010
Microsoft Visual Studio 2010 offers more to developers than any other
Visual Studio release. Work more productively and collaboratively-with
greater control over your work at every step. The Beta 2 can give you a
head start on achieving efficiency.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|