Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

Registration form example to insert user details in database using asp.net

Oct 24, 2010
Introduction

Here I will explain how to insert registered user details in database and how to get output parameters returned by SQL Query in asp.net.

Description

I have one registration form that give a chance to register new user .In registration form user needs to enter fields UserName, Password, Confirm Password like this I have nearly ten fields are there now I need to check whether this username already exists or not if username not exists I need to register user otherwise I need to display message like username already exists I am doing this thing using query. Here is the link it will explain how to write sql query to return output parameters 

http://www.aspdotnet-suresh.com/2010/10/introduction-here-i-will-explain-how-to.html

Now I need to display that output parameter message during user registration in asp.net. How to get that output parameter returned by SQL query.

To get output parameters in asp.net we need to write statements like this in codebehind

cmd.Parameters.Add("@ERROR", SqlDbType.Char, 500);
cmd.Parameters["@ERROR"].Direction = ParameterDirection.Output;
string message = (string) cmd.Parameters["@ERROR"].Value;
Here @ERROR is output parameter name returned from query

For sample design your aspx page like this 

aspx page

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>OutPut Pasrameters Sample</title>
</head>
<body>
<form id="form1" runat="server">  
<table align="center">
<tr>
<td></td>
<td align="right" >
</td>
<td align="center">
<b>Registration Form</b>
</td>
</tr>
<tr>
<td></td>
<td align="right" >
<asp:Label ID="lbluser" runat="server" Text="Username"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtuser" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td></td>
<td align="right" >
<asp:Label ID="lblpwd" runat="server" Text="Password"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtpwd" runat="server" TextMode="Password"></asp:TextBox>
</td>
</tr>
<tr>
<td></td>
<td align="right" >
<asp:Label ID="lblcnfmpwd" runat="server" Text="Confirm Password"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtcnmpwd" runat="server" TextMode="Password"></asp:TextBox>
</td>
</tr>
<tr>
<td></td>
<td align="right">
<asp:Label ID="lblfname" runat="server" Text="FirstName"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtfname" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td></td>
<td align="right">
<asp:Label ID="lbllname" runat="server" Text="LastName"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtlname" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td></td>
<td align="right">
<asp:Label ID="lblemail" runat="server" Text="Email"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td></td>
<td align="right" >
<asp:Label ID="lblCnt" runat="server" Text="Phone No"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtphone" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td></td>
<td align="right" >
<asp:Label ID="lbladd" runat="server" Text="Location"></asp:Label>
</td>
<td align="left">
<asp:TextBox ID="txtlocation" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td></td>
<td></td>

<td align="left" ><asp:Button ID="btnsubmit" runat="server" Text="Save"
onclick="btnsubmit_Click" />
<input type="reset" value="Reset" />
</td>
</tr>
<tr>
<td></td>
<td></td>
<td>
<span style= "color:Red; font-weight :bold"> <asp:Label ID="lblErrorMsg" runat="server"></asp:Label></span>
</td>
</tr>
</table>
</form>
</body>
</html>
In Codebehind write following code in btnsubmit_Click like this 

Codebehind


protected void btnsubmit_Click(object sender, EventArgs e)
{
if (txtpwd.Text == txtcnmpwd.Text)
{
string UserName = txtuser.Text;
string Password = txtpwd.Text;
string ConfirmPassword = txtcnmpwd.Text;
string FirstName = txtfname.Text;
string LastName = txtlname.Text;
string Email = txtEmail.Text;
string Phoneno = txtphone.Text;
string Location = txtlocation.Text;
string Created_By = txtuser.Text;
SqlConnection con = new SqlConnection("Data Source=MYCBJ017550027;Initial Catalog=MySamplesDB;Integrated Security=True");
con.Open();
SqlCommand cmd = new SqlCommand("sp_userinformation", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@UserName", UserName);
cmd.Parameters.AddWithValue("@Password", Password);
cmd.Parameters.AddWithValue("@FirstName", FirstName);
cmd.Parameters.AddWithValue("@LastName", LastName);
cmd.Parameters.AddWithValue("@Email", Email);
cmd.Parameters.AddWithValue("@PhoneNo", Phoneno);
cmd.Parameters.AddWithValue("@Location", Location);
cmd.Parameters.AddWithValue("@Created_By", Created_By);
cmd.Parameters.Add("@ERROR", SqlDbType.Char, 500);
cmd.Parameters["@ERROR"].Direction = ParameterDirection.Output;
cmd.ExecuteNonQuery();
message = (string) cmd.Parameters["@ERROR"].Value;
con.Close();
}
else
{
Page.RegisterStartupScript("UserMsg", "<Script language='javascript'>alert('" + "Password mismatch" + "');</script>");
}
lblErrorMsg.Text = message;
}
Here sp_userinformation is name of stored procedure created in database and@ERROR is output parameter name returned by query if you want to write query to insert data and return output parameters check this link

Click Here

After completion of everything run your page that will appear like this 

Demo


If you want sample code 

Download sample code attached

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

59 comments :

Nikoo said...

Hi, you have answered my question in
http://forums.asp.net/t/1648768.aspx
Thanks, I’m not sure why I get error when I try to return a value I have a new post in
http://forums.asp.net/t/1651886.aspx
with the code. Can you please help me.
My email address is: nikoo56@yahoo.com
Thanks!

Anonymous said...

u r genius if i want to learn complete asp.net from what should i do.....????

Suresh Dasari said...

hi if you want to learn complete .NET first you should start doing all the sample mentioned in this blog because i covered all the samples based on concepts. Once you complete all the samples you will get good knowledge on .NET first thing you should start doing samples.

uyir said...

hey everything is working good, but while signing in it shows no eroor but didnt move to the redirection page , please guide me

uyir said...

sorry everything is worked fine . i found out my error , thanks for your tutorial , pls don stop

sheshagiri said...

sir show about encryption/decryption value of textbox while inserting/retriving the values from database

Suresh Dasari said...

@Sheshagiri...
Check this article
http://www.aspdotnet-suresh.com/2010/12/introduction-here-i-will-explain-how-to_28.html

Anonymous said...

sir wat if i use vb.net for the same function. how the code will be like??

shalinirajapandy said...

Please Help Me How to Redirect the Page.... By Using this Coding

Anonymous said...

Sir, i have created an user registration form in html. and i want to save the details to MS SQL Server using ASP or any other technology. And i want to run the page only using html. help me. Thank you.

mpaul said...

Hi sir suresh can you please add vb.net code. thanks!

Balaji said...

Hello suresh sir
this info is very useful for me but i want one more page coding for forgot password using security question and data of birth..

Anonymous said...

sir i want to convert this registeration form into pdf..plz help me...

Anonymous said...

The request for procedure 'sp_userinformation' failed because 'sp_userinformation' is a table object.

what does it mean? if u have time plz must reply...

Anonymous said...

how to store text file into sql server database using c# windows application

Anonymous said...

how to separating a word in text file and stored by separate column into sql server database using c# windows application.. plz reply.. thank u.....

Anonymous said...

when i use this code it shows message doesn't exist in current context.what is the problem.Pls help

Anusha Perike said...

hii ..sir iam Anusha fresher , i created one asp.net page (login form contains userid , password&login button)how to execute that by using database sql server need commands plzz reply..

Anonymous said...

i want code to add comments in asp page.... just like the comment i m posting here... can any1 help....

Anonymous said...

how can I join u on facebook.

Benard Koech said...

hi sir please help me create a login form using the data from the signup database

Anonymous said...

when i try putting lblErrorMsg.Text = message;
it shows me error saying "message" does not exist in current context.

Help me with the same

Priyanka Dongare said...

sir please help me to create registration form with Radio button and datepicker

Sumi said...

it gives me an error saying 'message does not exist in the context'.....Please help

Anonymous said...

I found the error "A field initializer cannot reference the non-static field, method or property.."

Vatsal Shah said...

nice post...you can visit following link to get full proof code of how to store data in database using stored procedure and 3-tier architecture...

Click Here

Ameen Chaabani said...
This comment has been removed by the author.
Ameen Chaabani said...
This comment has been removed by the author.
Unknown said...

hey can u please provide the code on button onclick in vb,since the one you have provided is in c#

Swabhiman said...

Sir Please Help Me To Make A Project On A Social Networking Website Project For College Using Asp.net, C# in Visual Studio 2010 along with Ms Sql Server 2005. Please Provide Me The Source Code For The Website.

awey said...

suresh please i need it video and document upload and download form the database

Anonymous said...

sir this is C# or VB?

Jessy said...

Sir.. how to fix the 'message'?
The name 'message' does not exist in the current context.

http://s11.postimg.org/kh97a30r7/error_msg.jpg

Anonymous said...

I want the same code in vb

bejjarapu venu said...

when i try putting lblErrorMsg.Text = message;
it shows me error saying "message" does not exist in current context.
pls help me

Nikunj Prajapati said...

Error in line using vb.nt Please help me
cmd.Parameters["@ERROR"].Direction = ParameterDirection.Output;

Shanawaj Ansari said...

sir i am new to asp.net c# and i want to save data from asp page to sqlserver2008 from radiobutton,dropdownlist,checkbox and datetimepicker so plz help me with the coding...

Abu-Safiyya said...

Hello Sir Suresh Dasari,
Please could you help me with the vb.net version of this code, because I got error in the first line:
cmd.Parameters.Add("@ERROR", SqlDbType.Char, 500)

Thank you very much for the help

Senthil said...

I have a form with fields outside gridview and some fields inside gridview.Is it possible to save all the fields within the form to a database???Kindly provide a solution.Thanks in advance

Nidhi Gupta said...

hey i want to develop registrtion form like this we alreday have the fade text like first name as in facebook registration page and as we enter our deatils that fade text moves away ...is this possible to create this kind of registration page in asp.net??

Sooper said...

very nice articles......

Anonymous said...

Nice article for beginn to mid level. That is what a dynamic pages do all the time. Only would like to add that when I take end user's inputs I always use Server.HtmlEncode(sring taken from user). That very little line reduces lots of risks of users entering java script injections ot SQL hacking injections.

m.shantha Kumari said...

shanthi
very nice article sir....i want to know how to view the registered details...please provide registred data how to view...

protected void btnviewdetails_Click(object sender, EventArgs e)
{
Response.Redirect("~/ViewDetails.aspx");


}

Ganesh Jangam said...

count = cmd.ExecuteNonQuery(); returns negative value.....
plz help me sir

Gyan Prakash Jaiswal said...

The name 'message' does not exist in the current context.
help me sir

Gyan Prakash Jaiswal said...

Warning 2 'System.Web.UI.Page.RegisterStartupScript(string, string)' is obsolete: 'The recommended alternative is ClientScript.RegisterStartupScript(Type type, string key, string script). http://go.microsoft.com/fwlink/?linkid=14202' F:\Online Gift\WebApplication1\Registrationaspx.aspx.cs 62 21 WebApplication1
Help me sir

vishnu said...

i want to use also Date of birth in database can you help me how to write code in c# also using store procedure

Vivek G said...

in code behind c# coding.., 4th line from bottom.., what is "Page.RegisterStartupScript". bcz it show error in my app when i try this code. pls tell me brother... what to use or this is default ???

Shree jobs said...

Sir, Registration form running good.
after that i need to retrieve registration form data and print this registration form.
For example:
I am create a page 'application-form.aspx' and need to print this application form after the form is submitted for student.
please sir, reply.

Shree jobs said...

Thanks Sir..

Anonymous said...

thank u......

Sandesh Gurav said...

i like this
but i don't understand how to search data when enter employee id in search textbox and click on search button then get all details in one webpage and employee id show in lock or disable so we can edit all details but not edit ID

PLZ HELP ME HOW CAN I DO THIS....?

if you have url link plz give me

Anonymous said...

count = cmd.ExecuteNonQuery(); give the error as Invalid object name 'User_Information'.

Sandesh Gurav said...

thank u......

Sandesh Gurav said...

sir now i am create MLM PROJECT data entry web application.
E.G.: first i generate ID for 1st client then Like here IDS IME001, NOW WHEN IME001 PERSON IS BRING OTHER CLIENT, than i generate ID for 2nd person is IME002 and I set her of IME001 of left coloume, again IME001 is bring one more client his ID IS IME003 AND I SET HIS IMEOO1 OF RIGHT COLOUME

now how can i see when I SEARCH IME001 details left and right client ..?
I want display in SQL like this BUT when i go to sql and select table then result not come like see second table for example...?

TABLE : 1 I WANT TO SHOW IN SQL LIKE THIS
ime_id name left_Join right_join this is a right table
IME001 SANDESH IME002 IME003
IME 002 AMIT
IME003 SACHIN


TABLE ; 2 : THIS RESULT SHOW IN MY TABLE....?
IME_ID NAME IME_LEFT IME_RIGHT
IME001 SANDESH
IME002 AMIT
IME003 SACHIN

sir , now what can i do ....? how can ime002 and ime003 is insert into IME001 OF left and right cololum...?

please reply sir if you have any c# code and url for MLM web application give me

i am waiting your reply

Sandesh Gurav said...

sir plz reply my question

Sanjay Pardeshi said...

I m trying to insert record into database but password & confirm password in password mode doesnt saved in the database I have tried it with different browser also but it is not working ,so what I have to do to save it.

Unknown said...

hi sir how to send a confirmation email after registeration

Anonymous said...

source code for creating code 39 in vb.net

Give your Valuable Comments

Other Related Posts

© 2010-2012 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.