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; |
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>
|
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;
}
|
Click Here
After completion of everything run your page that will appear like this
Demo
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 Email
|
|||
|
|

Subscribe by RSS
Subscribe by Email
25 comments :
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!
u r genius if i want to learn complete asp.net from what should i do.....????
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.
hey everything is working good, but while signing in it shows no eroor but didnt move to the redirection page , please guide me
sorry everything is worked fine . i found out my error , thanks for your tutorial , pls don stop
sir show about encryption/decryption value of textbox while inserting/retriving the values from database
@Sheshagiri...
Check this article
http://www.aspdotnet-suresh.com/2010/12/introduction-here-i-will-explain-how-to_28.html
sir wat if i use vb.net for the same function. how the code will be like??
Please Help Me How to Redirect the Page.... By Using this Coding
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.
Hi sir suresh can you please add vb.net code. thanks!
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..
sir i want to convert this registeration form into pdf..plz help me...
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...
how to store text file into sql server database using c# windows application
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.....
when i use this code it shows message doesn't exist in current context.what is the problem.Pls help
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..
i want code to add comments in asp page.... just like the comment i m posting here... can any1 help....
how can I join u on facebook.
hi sir please help me create a login form using the data from the signup database
when i try putting lblErrorMsg.Text = message;
it shows me error saying "message" does not exist in current context.
Help me with the same
sir please help me to create registration form with Radio button and datepicker
it gives me an error saying 'message does not exist in the context'.....Please help
I found the error "A field initializer cannot reference the non-static field, method or property.."