Introduction
In this article we will show you how to create Store Procedure for registration using Windows Application in Visual Studio using C#.
Prerequisites
Visual Studio 2010/2012/2013/15/17, SQL Server 2005/08/2012
Project used version
VS2017, SQL SERVER 2012
Registration Form Stored procedure:
Add new stored procedure as shown below or paste the following stored procedure.
USE [DBLoginSystem]
GO
/****** Object: StoredProcedure [dbo].[spRegister] Script Date: 06-12-2018 12.01.52 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- User information
CREATE PROCEDURE [dbo].[spRegister](
@UserName varchar(50),
@Password varchar(50),
@Email varchar(50),
@RoleId int,
@Question varchar(50),
@Answer varchar(50),
@Result varchar(max) output
)
AS
BEGIN
SET NOCOUNT ON;
-- Email Id exist or not, If Email Id exist then returns "Email already exist !!" else Insert data into database and returns "Sucessfully Registratered !!"
if exists(select * from Users where Email = @Email)
begin
select @Result = 'Email already exists.';
end
else
-- getdate() , used get the current date and time is stored in CreatedDate Column.
-- isActivated, used to check whether account is locked or not, however initially user account is activated.
begin
INSERT INTO [dbo].[Users] ([UserName],[Password],[Email],[CreatedDate],[RoleID],
[SecretQuestion],[SecretAnswer],[isActivated])VALUES(@UserName,@Password,@Email,getdate(),
@RoleID,@Question,@Answer,1);
select @Result = 'Successfully Registred.';
end
END
GO
Description added as comment in below script.