Geeks With Blogs

News

Microsoft MVP


Moderator at CodeASP.NET


Quiz Master




free counters
Free counters
Added on January 19,2012


Follow Me @vmsdurano

A bit About Me



Disclaimer
The opinions expressed herein are my own personal opinions and does not represent the opinions of my employers. Nor does it represent the opinion of my dog, because I don’t have one.


Vinz' Blog (ProudMonkey) "Code, Beer and Music ~ my way of being a programmer"

This example shows how to create a very simple registration form in ASP.NET WebForms.


 

STEP1: Creating the Database.

The following are the basic steps on how to create a simple database in the Sql Server:

  1. Launch Sql Server Management Studion Express and then connect
  2. Expand the Databases folder from the Sql Server object explorer
  3. Right click on the Databases folder and select “New Database”
  4. From the pop up window, input the database name you like and click add
  5. Expand the Database folder that you have just added
  6. Right click on the Tables folder and select “New Table”
  7. Then add the following fields below:


 

Note: in this demo, I set the Id to auto increment so that the id will be automatically generated for every new added row. To do this select the Column name “Id” and in the column properties set the “Identity Specification” to yes.

Then after adding all the necessary fields, name your Table the way you like. Note that in this demo I name it “tblRegistration”

STEP2: Setting up the UI.

For the simplicity of this demo, I set up the UI like below in the WebForm:


ASPX:

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">
    <title>Sample Registration Page</title>
    <style type="text/css">
        .style1
        {
            width: 100%;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table class="style1">
            <tr>
                <td>Full Name:</td>
                <td>
                    <asp:TextBox ID="TxtName runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>Username:</td>
                <td>
                    <asp:TextBox ID="TxtUserName" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>Password:</td>
                <td>
                    <asp:TextBox ID="TxtPassword" runat="server"
                                 TextMode="Password"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>Re Password:</td>
                <td>
                    <asp:TextBox ID="TxtRePassword" runat="server"
                                 TextMode="Password"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>Address:</td>
                <td>
                    <asp:TextBox ID="TxtAddress" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>Age:</td>
                <td>
                    <asp:TextBox ID="TxtAge" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>Gender:</td>
                <td>
                <asp:DropDownList ID="DropDownList1" runat="server"
                                  AppendDataBoundItems="true">
                <asp:ListItem Value="-1">Select</asp:ListItem>
                <asp:ListItem>Male</asp:ListItem>
                <asp:ListItem>Female</asp:ListItem>
                </asp:DropDownList>
                </td>
            </tr>
        </table>
    </div>
    <asp:Button ID="Button1" runat="server" Text="Save" 
                             onclick="Button1_Click" />
    </form>
</body>
</html>

As you can see, the UI is very simple. Now let’s set up the connection string.

STEP3: Setting up the Connection String

In your web.config file set up the connection string there as shown below:

<connectionStrings>
    <add name="MyConsString" connectionString="Data Source=WPHVD185022-9O0;
                             Initial Catalog=MyDatabase;
                             Integrated Security=SSPI;"
                             providerName="System.Data.SqlClient" />
</connectionStrings>

Note: MyConsString is the name of the Connection String that we can use as a reference in our codes for setting the connection string later.

STEP4: Calling up the ConnectionString in our codes

Here’s the method for calling the connection string that was set up in the web.config file.

public string GetConnectionString(){
        //sets the connection string from your web config file "ConnString" is the name of your Connection String
        return System.Configuration.ConfigurationManager.ConnectionStrings["MyConsString"].ConnectionString;
}

STEP5: Writing the method for inserting the data from the registration page to the database.

In this demo, we are using the ADO.NET objects for manipulating the data from the page to the database. If you are not familiar with ADO.NET then I would suggest you to refer the following link below to get started:

ADO.NET Tutorial

Here’s the code block for inserting the data to the database.

private void ExecuteInsert(string name, string username, string password, string gender, string age, string address)
    {
        SqlConnection conn = new SqlConnection(GetConnectionString());
        string sql = "INSERT INTO tblRegistration (Name, UserName, Password, Gender, Age, Address) VALUES "
                    + " (@Name,@UserName,@Password,@Gender,@Age,@Address)";

        try
        {
            conn.Open();
            SqlCommand cmd = new SqlCommand(sql, conn);
            SqlParameter[] param = new SqlParameter[6];
            //param[0] = new SqlParameter("@id", SqlDbType.Int, 20);
            param[0] = new SqlParameter("@Name", SqlDbType.VarChar, 50);
            param[1] = new SqlParameter("@UserName", SqlDbType.VarChar, 50);
            param[2] = new SqlParameter("@Password", SqlDbType.VarChar, 50);
            param[3] = new SqlParameter("@Gender", SqlDbType.Char, 10);
            param[4] = new SqlParameter("@Age", SqlDbType.Int, 100);
            param[5] = new SqlParameter("@Address", SqlDbType.VarChar, 50);
            
            param[0].Value = name;
            param[1].Value = username;
            param[2].Value = password;
            param[3].Value = gender;
            param[4].Value = age;
            param[5].Value = address;

            for (int i = 0; i < param.Length; i++)
            {
                cmd.Parameters.Add(param[i]);
            }

            cmd.CommandType = CommandType.Text;
            cmd.ExecuteNonQuery();
        }
        catch (System.Data.SqlClient.SqlException ex)
        {
            string msg = "Insert Error:";
            msg += ex.Message;
            throw new Exception(msg);
        }
        finally
        {
            conn.Close();
        }
}

STEP6: Calling the method ExecuteInsert()

You can call the method above at Button_Click event for saving the data to the database. Here’s the code block below:

protected void Button1_Click(object sender, EventArgs e){
        if (TxtPassword.Text == TxtRePassword.Text)
        {
            //call the method to execute insert to the database
            ExecuteInsert(TxtName.Text, 
                          TxtUserName.Text, 
                          TxtPassword.Text, 
                          DropDownList1.SelectedItem.Text, 
                          TxtAge.Text, TxtAddress.Text);
            Response.Write("Record was successfully added!");
            ClearControls(Page);
        }
        else
        {
            Response.Write("Password did not match");
            TxtPassword.Focus();
        }
}

As you can see from the above code block, we check the value of the TxtPassword and TxtRePassword to see if match. If it match then call the method ExecuteInsert else display the error message stating that the “Password did not match”.

You also noticed that we call the method ClearControls for clearing the Text fields in the page. See the code block below for the ClearControls method:

public static void ClearControls(Control Parent){

        if (Parent is TextBox)
        { (Parent as TextBox).Text = string.Empty; }
        else
        {
            foreach (Control c in Parent.Controls)
                ClearControls(c);
        }
}

That’s it! Hope you will find this example useful!

 

Technorati Tags: ,,
Posted on Thursday, April 30, 2009 8:09 AM ADO.NET , ASP.NET , C# | Back to top


Comments on this post: Creating a Simple Registration Form in ASP.NET

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
Very helpful, thanks!
Left by G on Jul 20, 2009 4:23 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
It was really useful , properly explained. Thank you!
Left by Pinaz on Jul 28, 2009 8:45 AM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...

string sql = "INSERT INTO tblRegistration (Name, UserName, Password, Gender, Age, Address) VALUES "
+ " (@Name,@UserName,@Password,@Gender,@Age,@Address)";
giving the error new Line constant
..........?

any help?
Left by shini on Aug 07, 2009 1:08 AM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
hi this is very helpful to beginners
thank you
Left by raghupalreddy on Sep 20, 2009 7:19 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
Thanks, that was really useful. In fact i adapted the function to vb and it works great.

However, in my users' table i have used a numeric surrogate primary key (in order to allow users to change usernames without orphaning records) and as a result accounts with duplicate usernames can coexist. any ideas of how to prevent that please?

in fact i have thought of running another query to check for occurences of the username before attempting to insert, though i have not really managed to do it.

Anyways thanks a lot, it really helped :)

Left by Sephiro on Nov 03, 2009 8:19 AM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
heh nice! with your help i not only managed to complete the registration form, but the login as well (uses the same principle as in the forum topic you linked to, just a matter of adding a parameter to the query for the password)

anyways thanks again man, you rock ^_^
Left by Sephiro on Nov 04, 2009 9:17 AM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
It was very Fantastic in practical,hope constant help is expected in future,thnks
Left by shoukat ali on Dec 10, 2009 1:16 AM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
Sir i have a problem figuring it out, just a newbie but as I look into the code I have a clearer view of the picture the problem is I'm having a hard time putting the pieces together. Can you please me the complete code to where piece should belong.
Left by Leonila on Dec 10, 2009 7:42 AM

# Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
Sir where I have to put all this code coze I dont have any idea I knw only ASPX code & web config code but the rest of the code where I have to put Plz. give me complete set of code and where is it goes??

Thanking U.
Left by Jignesh Parmar on Jan 29, 2010 9:13 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
Very useful for me.
Thanks
I want another one .how can read this database data .helpme
Left by jackveera on Feb 01, 2010 6:53 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
When I am debbuging it says
Insert Error:Login failed for user
Left by niyati on Feb 08, 2010 5:22 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
Am getting this error even tho my web.config file is well set up


Keyword not supported: 'driver'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Keyword not supported: 'driver'.

Source Error:


Line 31: {
Line 32:
Line 33: SqlConnection conn = new SqlConnection(GetConnectionString());
Line 34:
Line 35:


Can advice please
Left by David on Feb 09, 2010 11:12 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
it will be very usefull to me
Left by stephan c on Feb 22, 2010 12:23 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
Great ..thanks it was of great help...since i wanted a simple webform for my proof of concept for a project...and it exactly fit the criteria..thanks
Left by shyam on Mar 01, 2010 11:47 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
Thanks,But how to implement or integrate Captcha in a registration form.I need the complete code.

Left by satyapriya on Mar 18, 2010 1:19 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
==================== for david ==================

hello david
add this namespaces to your project to continu...
using System.Data;
using System.Data.SqlClient;

****************

note:
c# is Case sensitive

****************

===============================================
Left by hassan on Mar 19, 2010 5:35 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
good job!!... hope can see more awesome example:)
Left by maycy on Mar 19, 2010 11:45 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
Can this page be link to ASP.NET 2.0
Left by sy on Mar 22, 2010 4:30 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
how can we enter complete date in data base..using 3 dropdown list...ist dropdown list shows days 2nd months and 3rd shows years???
Left by Tamoor Virk on Mar 23, 2010 3:15 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
Hai...
I'm new in APS.net and I'm using VB. I try follow and create just like the example. I'm done create the UI, and the code should pun in the web config and code behind page right. Can I just copy and paste it. Can anyone help decode the code into VB.
Left by mizsdora on Mar 27, 2010 10:29 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
I'm done decode the coding into VB, but it have error. Can anyone check and correct the code.


Private Sub ExecuteInsert(ByVal name As String, ByVal username As String, ByVal password As String, ByVal gender As String, ByVal age As String, ByVal address As String)
Dim conn As SqlConnection = New SqlConnection(GetConnectionString)
Dim sql As String = ("INSERT INTO tblRegistration (Name, UserName, Password, Gender, Age, Address) VALUES " + " (@Name,@UserName,@Password,@Gender,@Age,@Address)")
Try
conn.Open
Dim cmd As SqlCommand = New SqlCommand(sql, conn)
Dim param() As SqlParameter
6
'param[0] = new SqlParameter("@id", SqlDbType.Int, 20);
param(0) = New SqlParameter("@Name", SqlDbType.VarChar, 50)
param(1) = New SqlParameter("@UserName", SqlDbType.VarChar, 50)
param(2) = New SqlParameter("@Password", SqlDbType.VarChar, 50)
param(3) = New SqlParameter("@Gender", SqlDbType.Char, 10)
param(4) = New SqlParameter("@Age", SqlDbType.Int, 100)
param(5) = New SqlParameter("@Address", SqlDbType.VarChar, 50)
param(0).Value = name
param(1).Value = username
param(2).Value = password
param(3).Value = gender
param(4).Value = age
param(5).Value = address
Dim i As Integer = 0
Do While (i < param.Length)
cmd.Parameters.Add(param(i))
i = (i + 1)
Loop
cmd.CommandType = CommandType.Text
cmd.ExecuteNonQuery
Catch ex As System.Data.SqlClient.SqlException
Dim msg As String = "Insert Error:"
msg = (msg + ex.Message)
Throw New Exception(msg)
Finally
conn.Close
End Try
End Sub
Left by mizsdora on Mar 28, 2010 8:09 AM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
I'm done making the UI, database and coding into web config. But, I have error of coding in code behind page. The error is in STEP5: Writing the method for inserting the data from the registration page to the database. Can anyone please explain to me more detail about this.
Left by mizsdora on Mar 29, 2010 1:06 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
Below is the code that I decode from C# into VB. But when I copy and paste this code into ASP.net I got error. Example of code that error is SqlConnection, SqlParameter and others.


Private Sub ExecuteInsert(ByVal name As String, ByVal username As String, ByVal password As String, ByVal gender As String, ByVal age As String, ByVal address As String)
Dim conn As SqlConnection = New SqlConnection(GetConnectionString)
Dim sql As String = ("INSERT INTO tblRegistration (Name, UserName, Password, Gender, Age, Address) VALUES " + " (@Name,@UserName,@Password,@Gender,@Age,@Address)")
Try
conn.Open
Dim cmd As SqlCommand = New SqlCommand(sql, conn)
Dim param() As SqlParameter
6
'param[0] = new SqlParameter("@id", SqlDbType.Int, 20);
param(0) = New SqlParameter("@Name", SqlDbType.VarChar, 50)
param(1) = New SqlParameter("@UserName", SqlDbType.VarChar, 50)
param(2) = New SqlParameter("@Password", SqlDbType.VarChar, 50)
param(3) = New SqlParameter("@Gender", SqlDbType.Char, 10)
param(4) = New SqlParameter("@Age", SqlDbType.Int, 100)
param(5) = New SqlParameter("@Address", SqlDbType.VarChar, 50)
param(0).Value = name
param(1).Value = username
param(2).Value = password
param(3).Value = gender
param(4).Value = age
param(5).Value = address
Dim i As Integer = 0
Do While (i < param.Length)
cmd.Parameters.Add(param(i))
i = (i + 1)
Loop
cmd.CommandType = CommandType.Text
cmd.ExecuteNonQuery
Catch ex As System.Data.SqlClient.SqlException
Dim msg As String = "Insert Error:"
msg = (msg + ex.Message)
Throw New Exception(msg)
Finally
conn.Close
End Try
End Sub
Left by mizsdora on Mar 29, 2010 4:02 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
I've got error of CommandType. What should I do...
Left by mizsdora on Mar 29, 2010 5:06 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
hi, i came across the same problem as yours, but i found a solution,
That's in your web.config, the connection string needs to have --> Integrated Security=SSPI
Left by xTheng on Mar 29, 2010 11:12 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
How do you setup the connection for mysql?
Left by Jett on Mar 30, 2010 3:41 AM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
I'm not using mysql. I'm using sql server. I make a new connection to database.
Left by mizsdora on Mar 30, 2010 5:08 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
Hello, I found the article very useful but on applying the code, I got the following error
" 'int' does not contain a definition for 'Text' and no extension method 'Text' accepting a first argument of type 'int' could be found (are you missing a using directive or an assembly reference?)"

I got ths error at ExecuteInsert, when the data is inserted into database, please help.
Left by Rishi on Mar 31, 2010 6:29 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
Yes. Finally it's done. Thanks for helping... ^_^
Left by mizsdora on Apr 03, 2010 8:23 AM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
Hello David,

The code was very nice but i m having this ERROR
Please Solve this ASAP





System.FormatException was unhandled by user code
Message="Failed to convert parameter value from a String to a Int32."
Source="System.Data"
StackTrace:
at System.Data.SqlClient.SqlParameter.CoerceValue(Object value, MetaType destinationType)
at System.Data.SqlClient.SqlParameter.GetCoercedValue()
at System.Data.SqlClient.SqlParameter.Validate(Int32 index, Boolean isCommandProc)
at System.Data.SqlClient.SqlCommand.BuildParamList(TdsParser parser, SqlParameterCollection parameters)
at System.Data.SqlClient.SqlCommand.BuildExecuteSql(CommandBehavior behavior, String commandText, SqlParameterCollection parameters, _SqlRPC& rpc)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at SubmitForm2.ExecuteInsert(String name, String username, String password, String gender, String age, String address) in f:\SonamPractiseProjects\ASPXFormSubmition\SubmitForm2.aspx.cs:line 99
at SubmitForm2.Button1_Click(Object sender, EventArgs e) in f:\SonamPractiseProjects\ASPXFormSubmition\SubmitForm2.aspx.cs:line 28
at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
InnerException: System.FormatException
Message="Input string was not in a correct format."
Source="mscorlib"
StackTrace:
at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
at System.String.System.IConvertible.ToInt32(IFormatProvider provider)
at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
at System.Data.SqlClient.SqlParameter.CoerceValue(Object value, MetaType destinationType)
InnerException:
Left by Sonam Diwate on Apr 06, 2010 3:42 PM

# re: Create full registration form
Requesting Gravatar...
how to saved username and password in other table at that time plz replly soon
Left by gopal on Apr 06, 2010 4:41 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
i m having these errors will u please guide me?
Error 1 Sections must only appear once per config file. See the help topic <location> for exceptions. (C:\Documents and iSettings\Administrator\Desktop\website\web.config line 13)
Error 2 C:\Documents and Settings\Administrator\Desktop\website\ContentPages\Default.aspx: ASP.NET runtime error: Sections must only appear once per config file. See the help topic <location> for exceptions. (C:\Documents and Settings\Administrator\Desktop\website\web.config line 13) C:\Documents and Settings\Administrator\Desktop\website\ContentPages\Default.aspx 1 1 C:\...\website\
Left by poonam on Apr 09, 2010 5:21 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
Hi Sir,

When i am executing the above code , while running i got 1 warning adn 1 runtime error
:1. Null Reference Exception was unhandled by usercode ---Use the New keyword to create an object instance.
2.Validation(Asp.net): If this attribute value is enclosed in quotation marks, the quotation marks must match...

Please help me to solve this problem..

Thanks in Advance...
Left by Jayachandra on Apr 25, 2010 1:45 AM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
Hi Sir,
Please find the Issue Below:

System.NullReferenceException was unhandled by user code
Message="Object reference not set to an instance of an object."
Source="App_Web_9lxvgveb"
StackTrace:
at _Default.GetConnectionString() in c:\Documents and Settings\Balaraj\My Documents\Visual Studio 2008\WebSite1\registration\Default.aspx.cs:line 23
at _Default.ExecuteInsert(String name, String username, String password, String gender, String age, String address) in c:\Documents and Settings\Balaraj\My Documents\Visual Studio 2008\WebSite1\registration\Default.aspx.cs:line 31
at _Default.Button1_Click(Object sender, EventArgs e) in c:\Documents and Settings\Balaraj\My Documents\Visual Studio 2008\WebSite1\registration\Default.aspx.cs:line 134
at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
InnerException:
Left by Jayachandra on Apr 25, 2010 10:45 AM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
sir i need ur help noone help me i dont know why everyone discourage me
Left by amit mago on May 13, 2010 9:49 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
sir i need ur help noone help me i dont know why everyone discourage me do u have ur email id
Left by amit mago on May 13, 2010 10:20 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
Hi I am new in asp and using VB ... I am using this code for my project... but while i run my page .. it gives a error: Insert Error: Login Failed for User
And pointing to line 83 in ExecuteInsert. Can Someone help me finding the erroe Plese!!!!!!

Below is my total code: ( Code behind )

Partial Class addcustomerdata
Inherits System.Web.UI.Page

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim inputpass As String
inputpass = TxtPassword.Text

If (TxtPassword.Text = TxtRePassword.Text) Then

ExecuteInsert(TxtfName.Text, TxtlName.Text, TxtUserName.Text, TxtPassword.Text, TxtSuburb.Text, TxtPostcode.Text, DropDownList1.SelectedItem.Text, TxtEmail.Text, TxtWeight.Text, TxtAddress.Text)



Response.Write("Record was successfully added!")



'ClearControls(Page)



Else



Response.Write("Password did not match")

TxtPassword.Focus()


End If


End Sub



Private Sub ExecuteInsert(ByVal fname As String, ByVal lname As String, ByVal address As String, ByVal suburb As String, ByVal postcode As String, ByVal email As String, ByVal sex As String, ByVal weight As String, ByVal username As String, ByVal password As String)
Dim conn As SqlConnection = Nothing
Dim connection As String = System.Configuration.ConfigurationManager.ConnectionStrings("MyConnString").ConnectionString
conn = New SqlConnection(connection)


Dim sql As String = ("INSERT INTO customer (firstname, lastname, suburb, postcode, email, username, password, sex, address) VALUES " + " (@fName,@lName,@UserName,@Password,@Sex,@Email,@Postcode,@Suburb,@Weight,@Address)")
Try
conn.Open()
Dim cmd As SqlCommand = New SqlCommand(sql, conn)
Dim param() As SqlParameter
10:

param(0) = New SqlParameter("@fName", SqlDbType.VarChar, 50)
param(1) = New SqlParameter("@lName", SqlDbType.VarChar, 50)
param(2) = New SqlParameter("@Address", SqlDbType.VarChar, 50)
param(3) = New SqlParameter("@Suburb", SqlDbType.VarChar, 50)
param(4) = New SqlParameter("@Postcode", SqlDbType.Int, 100)
param(5) = New SqlParameter("@Email", SqlDbType.VarChar, 50)
param(6) = New SqlParameter("@Sex", SqlDbType.VarChar, 50)
param(7) = New SqlParameter("@Weight", SqlDbType.Int, 50)
param(8) = New SqlParameter("@UserName", SqlDbType.VarChar, 50)
param(9) = New SqlParameter("@Password", SqlDbType.VarChar, 50)
param(0).Value = fname
param(1).Value = lname
param(2).Value = address
param(3).Value = suburb
param(4).Value = postcode
param(5).Value = email
param(6).Value = sex
param(7).Value = weight
param(8).Value = username
param(9).Value = password
Dim i As Integer = 0
Do While (i < param.Length)
cmd.Parameters.Add(param(i))
i = (i + 1)
Loop
cmd.CommandType = CommandType.Text
cmd.ExecuteNonQuery()
Catch ex As System.Data.SqlClient.SqlException
Dim msg As String = "Insert Error:"
msg = (msg + ex.Message)
Throw New Exception(msg)
Finally
conn.Close()
End Try
End Sub
End Class


Web.config File :

<connectionStrings>
<add name="MyConnString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\project.mdf; " providerName="System.Data.SqlClient"/>
</connectionStrings>

Left by Raj on May 24, 2010 1:10 AM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
Sir,

I am egare to learn .net, so mean time im started learning on own with sql server and while coding part.. i just tried with registration page... but i was getting many error..i tried fixed by searching in google and though getting error.. so i must learn well.. tell me the best website or tutorial where can learn ASP.net, c# etc.. im helplesss i doesnt have any guidance.. please help me.. will be greatful to u..

thanks in Advance
Left by Arun on May 28, 2010 4:02 AM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
Great tutorial. Just the right amount of detail for someone new to C#/asp.net to follow. Thanks for the help.
Left by TPG on Jun 08, 2010 2:09 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
I face a Configuration error when I run the application. Anyone can advice my error. Please see the error below. Thanks in advance.

Server Error in '/' Application.
Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message: Unrecognized configuration section system.web/connectionStrings.

Source Error:

Line 17: <system.web>
Line 18:
Line 19: <connectionStrings>
Line 20:
Line 21: <add name="MyConsString" connectionString="Data Source=SCBEAPPSVR1\SQLEXPRESS;Initial Catalog=OnlineLogBook;Integrated Security=SSPI;" providerName="System.Data.SqlClient" />

Left by Teddy on Jun 14, 2010 5:00 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
Server Error in '/' Application.
Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

Parser Error Message: Could not load type 'Online_Log_Book._Default'.

Source Error:

Line 1: <%@ Page Language="C#" AutoEventWireup="false" CodeBehind="Default.aspx.cs" Inherits="Online_Log_Book._Default" %>
Line 2:
Line 3: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


Source File: /Default.aspx Line: 1

Version Information: Microsoft .NET Framework Version:2.0.50727.4200; ASP.NET Version:2.0.50727.4205
Left by Teddy on Jun 15, 2010 9:43 AM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
how can i create a web form with asp.net scripting in c#.
how to make form with asp.net scripting in c#?
Left by rejith on Jun 29, 2010 3:27 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
I'm getting a "System.IndexOutOfRangeException: Index was outside the bounds of the array" error. Googled the hell out of it and can;t find a fix. any ideas?
Left by tmiranda on Jul 02, 2010 3:23 AM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
I'm getting some errors like this

Error 1 The name 'SqlDbType' does not exist in the current context D:\Project_Website\Sign_Up.aspx.cs 65 69 D:\Project_Website\


Error 12 The name 'CommandType' does not exist in the current context D:\Project_Website\Sign_Up.aspx.cs 100 30 D:\Project_Website\


CAN PLZ HELP ME
Left by Charles on Jul 20, 2010 6:30 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
thanks 4 code
Left by Jennifer F on Sep 01, 2010 11:24 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
Hi, this is really very helpful.
Thank u very much
Left by Abi on Sep 27, 2010 4:03 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
thanks alot.............very useful and valuable feedback
Left by sandhya on Sep 27, 2010 6:33 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
It was really helpful for my project......... Thanks a lot..
Left by lakshmi on Nov 13, 2010 7:24 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
thnaks nice code, i have problem if i enter the age field empty and press the button i am getting error how to solve it in sqlserver
Left by nirmal on Nov 30, 2010 1:02 AM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
@nirmal,

Your options would be:

1. Don't allow users to hit submit when fields are empty. You can do some validations on it first before saving the data to the database.
2. Or in you database table you can set Allow Null for Age Column.
Left by Vinz on Nov 30, 2010 12:23 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
I tried the above code and received the following error:

Keyword is not valid as an identifier.

public string GetConnectionString()

how can public not be valid?
Left by Fred on Dec 04, 2010 3:01 AM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
very nice tutorial "Creating a Simple Registration Form in ASP.NET ".

how many files i have to create, in which file should i paste the code of STEP4: STEP5: STEP6
or can you please give Zip of "Creating a Simple Registration Form in ASP.NET.

I am trying this code since from lonf 2 weeks, does not work
Left by Danish on Dec 04, 2010 3:13 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
@Danish,

Sorry but I don't provide down-loadable samples at the moment.
Just write the codes mentioned in STEP4, STEP5 and STEP6 in the code behind file.

Also if you are having problems integrating this in your application, I'd suggest you to post it at the forums to get more help.

Thanks!
Left by Vinz on Dec 04, 2010 6:44 PM

# getting Error . Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS1518: Expected class, delegate, enum, interface, or struct

Source Error:



Line 20:
Line 21:
Line 22: public string GetConnectionString()
Line 23:
Line 24: {


Source File: d:\VS 8\reg\Default.aspx.cs Line: 22




Left by ada on Dec 19, 2010 9:59 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
@ada,

Be sure that you placed your the method GetConnectionString() within the class block.
Left by Vinz on Dec 20, 2010 12:44 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
i get a error with all of the attributes such as TxtName.text --- it says it does not exist in current context and fails to compile :(


//call the method to execute insert to the database

ExecuteInsert(TxtName.Text, TxtUserName.Text, TxtPassword.Text, DropDownList1.SelectedItem.Text, TxtAge.Text, TxtAddress.Text);
Left by louis on Jan 04, 2011 8:22 PM

# re: Creating a Simple Registration Form in ASP.NET for online voting at campus
Requesting Gravatar...
hello...
pls snd the code as fast as possible.
Left by anila paul on Jan 12, 2011 5:37 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
it was very helpful for me....
Left by veera on Jan 21, 2011 10:59 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
sir this coding is really rocks i have used it and find wonderfull result
Left by assad on Jan 30, 2011 4:48 AM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
i have creating register form and field name is pincode,stateand city my problem is that we enter pin code automatically display city name and state name plz send code in c# on my mail id
thanks&regards
chirag shah
Left by chirag on Feb 08, 2011 7:49 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
I understand the way your going here but i'm unsure where to paste certain parts of the code. Could you give me some more information where to put the PART 4 & PART 5 parts of code ?

Thanks in advance !
Left by Tim Robberecht on Mar 12, 2011 4:14 AM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
i understand above code but how to use session for this user sign up form.. please tell me,


i am waiting for ur reply...
thanks and regards mohan...
Left by mohan on Mar 15, 2011 3:26 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
Thanks.This was really useful for me. Thanx a lot.....
Left by Saritha Unnithan on Mar 25, 2011 5:33 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
Thanks for the nice code. Got it to work - but...
How do you encrypt the password in the database ??
To clarify...
I made a login form from trh tools, and when you write a correct username and password (and point to the right database) i will not login.

Looking ind the database made by .Net, the password is Encrypted...
Can i make an encryption of the password, and how ????

Thanks!!
Left by HEWI on Apr 13, 2011 5:43 PM

# creating an calender for trip planing
Requesting Gravatar...
sir
I want to make a calender gor trip planing.with these rerquirment


1make a calender with each selected date it show available holliday package

3 On the frontend, To view the holiday offer, the user will have to enter his Email, Name and phone number.
6. Users name, email and phone number will also get stored in the admin

Regards,
Left by pankaj kumar trivedi on Apr 16, 2011 9:06 AM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
thanks. this good one. i want how to show grid view insert,update,delete codings.
Left by bhagyaraj on May 02, 2011 7:24 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
@bhagyaraj,

Check these examples to get started:

http://geekswithblogs.net/dotNETvinz/archive/2009/02/22/gridview-insert-edit-update-and-delete--the-ado.net-way.aspx - If using BoundField Columns

http://geekswithblogs.net/dotNETvinz/archive/2009/06/10/adding-rows-in-gridview-with-edit-update-and-delete-functionality.aspx - If using TemplateField Columns
Left by Vinz on May 02, 2011 7:42 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
It's very useful.
Left by Axentar on May 16, 2011 7:33 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
thanks a lot! it works!
Left by sklazer on May 16, 2011 7:52 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
its helful
Left by Anand on May 17, 2011 6:25 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
hi
sir
i want to create registration form and i write code but it not execute
Left by Ramesh on May 20, 2011 3:48 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
@Ramesh,

Have you tried debugging your codes? Set a break point at click event of the button to verify if it hits there when you click it. If it doesn't fire then make sure you wired up the onlick event to your button.
Left by Vinz on May 20, 2011 5:23 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
I got same problem as Louis but unfortunately there were no response to his problem

ExecuteInsert(TxtName.Text, TxtUserName.Text, TxtPassword.Text, DropDownList1.SelectedItem.Text, TxtAge.Text, TxtAddress.Text);

The message is like:
Error 5 The name 'TxtUserName' does not exist in the current context

(Are you being selective and helping people?)
Left by moffzar on Jun 27, 2011 6:08 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
@moffzar,

Be sure that the ID TxtUserName does exist in your WebForm. Also check if your ASPX.CS is pointing to your Code behind properly.

Note: If you want a prompt response for any help I'd suggest you to post your issue at the forums (forums.asp.net or codeasp.net/forums) and state your problem. Please note that I also work for a living so delayed reponses may happen.

Thank you.
Left by Vinz on Jun 27, 2011 6:37 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
I too have the textboxes not existing in current context. I ve tried all sorts but no success. It obviously has to do with some mistake or omission on this post since there are a lot of people complaining. Maybe its a mistake only newbies can fail to notice (I know i am). But fact is when you putt up this kind of thing you have to take also into account newbies.

So please have the common decency to test your code (i know this wasn't cause there is at least one typo i ve spotted) and then put the code as a "whole" instead of skipping the headings or fragmenting the code to make comments. (You could have used //* comment *//)

I don't mean to come through so aggressive but I ve wasted two days trying to figure this one out and I sure I m not the only one.
Left by Alex on Jul 16, 2011 12:03 AM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
I really appreciate this explanation.
But i need a help that if i am inserting a new record than it should first check if the same user with same email id already exists or not.
if it exists than it should display duplicate user or email id.
what changes are to be made in above code.
will be very thankul for ur answer.
Left by vivek singh on Jul 20, 2011 1:54 AM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
@vivek,

Check my answer on this post: http://forums.asp.net/p/1339922/2711314.aspx

That you should give some idea to get started.
Left by Vinz on Jul 21, 2011 1:37 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
Really great for beginner. Thank you very much.
Left by Hannan on Jul 26, 2011 5:41 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
Great help, THANK U
Left by Kate on Aug 04, 2011 7:21 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
hiiii, i want to create a registration form in to linq plz help me
Left by chirag on Aug 31, 2011 3:01 AM

# i am creating registration form and edit the data base values in execution i can change no but not clear the first no detail
Requesting Gravatar...
plz help me
Left by lakshmi on Sep 13, 2011 3:40 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
I am a complete newbie in asp.net.plz tell me where do i insert the functions like getconnectionstrings() and the others.plz help
Left by Sujit warrier on Sep 13, 2011 9:32 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
thank you sir for uploading
Left by pritesh on Sep 26, 2011 9:36 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
thanks ,expecting like..........
Left by Rafi on Oct 17, 2011 3:44 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
This tutorial ia really helping.
I have been working pretty same way but getting exception in my code that is NullReference Exception not handled bu the user code.
This issue is occuring in my connection to SQL Server.
I will be gratefule if some one wanna help me on urgent basis.
Left by Ishfaque Memon on Oct 21, 2011 3:23 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
it is so much useful thank you very much
it help me know about asp.net thank you again !!!
Dani from the ancient Abyssinia
Left by tesfaye daniel on Oct 24, 2011 5:09 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
Syntax error in INSERT INTO statement.
can u help me


//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.OleDb;


namespace StajyerWebApp
{
public class DbCon1
{
private static OleDbConnection odc;

private static OleDbDataAdapter adp;

private static DataSet dt;



private static string db_yeri = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source= C:\\USDB\dbcon1.mdb";
//private static string db_yeri = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application.StartupPath.ToString() + "\\C:\Users\mbaykan\Documents\Visual Studio 2010\Projects\StajSoln\StajWebApp\App_Data";






public static void SqlData(string sorgu, string table_name)
{


odc = new OleDbConnection(db_yeri);

adp = new OleDbDataAdapter(sorgu, odc);

dt = new DataSet();

adp.Fill(dt, table_name);





}

public static DataTable Select(string sorgu)
{


odc = new OleDbConnection(db_yeri);
OleDbCommand comm = new OleDbCommand();
comm.Connection = odc;
comm.CommandText = sorgu;
DataTable dt = new DataTable();
using (odc)
{
odc.Open();
comm.CommandText = "Select * from Table1";
OleDbDataAdapter da = new OleDbDataAdapter(comm);
da.Fill(dt);
odc.Close();
}

return dt;
}

public static void DML(string sorgu)
{
odc = new OleDbConnection(db_yeri);
OleDbCommand comm = new OleDbCommand();
comm.Connection = odc;
comm.CommandText = sorgu;
DataTable dt = new DataTable();
using (odc)
{

comm.ExecuteNonQuery();
odc.Close();
}
}


}
}
Left by mehmet on Nov 04, 2011 4:14 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
i was execute same way but there is an error,

1)The name 'CommandType' does not exist in the current context
2)The name 'SqlDbType' does not exist in the current




param[0] = new SqlParameter("@Name", SqlDbType.VarChar, 50);

param[1] = new SqlParameter("@UserName", SqlDbType.VarChar, 50);

param[2] = new SqlParameter("@Password", SqlDbType.VarChar, 50);

param[3] = new SqlParameter("@Gender", SqlDbType.Char, 10);

param[4] = new SqlParameter("@Age", SqlDbType.Int, 100);

param[5] = new SqlParameter("@Address", SqlDbType.VarChar, 50);
Left by Murali on Nov 05, 2011 2:52 PM

# Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
i was execute same way but there is an error,

1)The name 'CommandType' does not exist in the current context
2)The name 'SqlDbType' does not exist in the current


Can you please suggest me to come out of the error !


param[0] = new SqlParameter("@Name", SqlDbType.VarChar, 50);

param[1] = new SqlParameter("@UserName", SqlDbType.VarChar, 50);

param[2] = new SqlParameter("@Password", SqlDbType.VarChar, 50);

param[3] = new SqlParameter("@Gender", SqlDbType.Char, 10);

param[4] = new SqlParameter("@Age", SqlDbType.Int, 100);

param[5] = new SqlParameter("@Address", SqlDbType.VarChar, 50);
Left by Murali on Nov 05, 2011 3:08 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
i need create, insert,update,delete i n that form
Left by MADASAMY on Nov 21, 2011 6:42 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
hello,
i am creating registration from and generate id in next page .
how to solve this problem.
thanks
Left by laxman on Dec 02, 2011 5:55 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
This is Completely Awesome for Beginners those who get idea for Registration !!
Left by Asp.net beginners on Dec 05, 2011 4:22 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
Hi, thanks sounds geat and looks just like what I need except I am a complete beginner.I have built the interface and the SQL table.Now I have no idea where to put the rest of the code, Can you email me how the code is supposed to look in teh web config and in the vb code for the form?Thanks a lot.
Left by Carlo Leonini on Dec 06, 2011 6:28 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
guys any one share here fulled coded page with guide so easy to download and change as we like

please shared demo pages in zip and guide pic or note
Left by niravmehta2009 on Dec 10, 2011 3:54 AM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
Please try to send the details of creating a registration page in asp.net
Left by Harish Kumar on Jan 04, 2012 12:31 AM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
This is best one article so far I have read online. I would like to appreciate you for making it very simple and easy. I have found another nice post related to this post over the internet which also explained very well. For more details you may check it by visiting this url.....

http://mindstick.com/Articles/c389febe-fceb-4cb9-a4d1-41259346f449/?Login%20Form%20in%20ASP.Net

Thanks everyone for your precious post!!
Left by Somesh Batra on Jan 09, 2012 5:18 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...

I have error in this statement, i can't know why?
please, help me

executeInsert (txtUserName.Text ,txtPassword .Text ,txtName.Text ,txtAge.Text ,ddlGender.SelectedItem.Text ,txtEmail.Text);
Left by bent on Jan 12, 2012 8:43 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
thank you thank you thank you
Left by MohammaD on Jan 13, 2012 4:28 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
This was extremely helpful! If you could really help me out, I was wondering what would change if I was using an ODBC Connection rather than a SQL Connection?
Left by James on Jan 13, 2012 11:51 PM

# Creating a animated Registration Form in ASP.NET
Requesting Gravatar...
please how to create animated registration form

for example
after entering the username it must be move a side and hide
Left by K.lohith kumar on Jan 30, 2012 3:02 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
Thanks for the straightforward example of data inserts -- and ClearControls! :)
Left by Tim Condit on Jan 31, 2012 5:11 AM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
Hi Can you please help.
How do I do it so that the function GetConnectionString() is stored in another file.
I have tried doing this but the file where I refer GetConnectionString() can't find the function.
Left by Karim on Feb 01, 2012 5:11 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
@karim,

You'll have to make your method as public so it can be accessed in another class. Check this post for example: http://geekswithblogs.net/dotNETvinz/archive/2008/02/01/creating-a-data-access-framework-again.aspx
Left by Vinz on Feb 01, 2012 5:48 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
thanks buddy.
Left by sulabh on Feb 10, 2012 5:45 AM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
i have one submit button is my form so i wanted that submit button to have two funtion:-
1. Add all the details in the database(Ms acess) that has been filled my da client
2. I want the form to be navigated to another form after clicking on the submit button
I am using asp.net
both of them works but when i write both of dem together only one of the function works
Left by ugyen dorji on Feb 13, 2012 4:25 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
sir help me ...same example i try in the system i got some errors 1)The name 'CommandType' does not exist in the current context
2)The name 'SqlDbType' does not exist in the current

plz help me...
Left by kishore on Feb 16, 2012 2:15 PM

# Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
i am creating one small web site with two fields can u givw coding for me
Left by Bali on Feb 24, 2012 5:06 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
Really this is a good article, which helps a lot for beginners as me as well as developer. I have checked another good article over the internet which also explained very well on creating login form in C#.Net. For more information on this post, please check out this url....
http://mindstick.com/Articles/543d4dea-c228-4fbc-a2af-2239a4a6db2d/?How%20To%20Create%20Login%20Form%20in%20CSharp%20.NET
Left by Jeet Verma on Feb 27, 2012 8:04 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
plz.give me..perfact coding of registerpage in sql inbuilt.with radio buton...
give answer on mail
Left by lipsa on Mar 12, 2012 5:27 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
hi vinz great article.vinz i ve one doubt about the method public static void ClearControls(Control Parent)u write this mthod but ur not keeping any button in UI page clear txtfields.pls tell me the method use.


thanks&regard
Hareesh.A

Left by hareesh on Mar 17, 2012 4:12 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
very heipful
Left by hema patankar on Mar 24, 2012 12:35 AM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
protected void btnSubmit_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["dbconnection"].ConnectionString);
con.Open();
SqlCommand cmd = new SqlCommand("select * from UserInformation where UserName =@username and Password=@password",con);
cmd.Parameters.AddWithValue("@username", txtUserName.Text);
cmd.Parameters.AddWithValue("@password", txtPWD.Text);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
if(dt.Rows.Count>0)
{
Response.Redirect("Details.aspx");
}
else
{
ClientScript.RegisterStartupScript(Page.GetType(), "validation", "<script language='javascript'>alert('Invalid Username and Password')</script>");
}
}
Left by zakir ughradar on Apr 12, 2012 1:14 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
protected void btnSubmit_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["dbconnection"].ConnectionString);
con.Open();
SqlCommand cmd = new SqlCommand("select * from UserInformation where UserName =@username and Password=@password",con);
cmd.Parameters.AddWithValue("@username", txtUserName.Text);
cmd.Parameters.AddWithValue("@password", txtPWD.Text);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
if(dt.Rows.Count>0)
{
Response.Redirect("Details.aspx");
}
else
{
ClientScript.RegisterStartupScript(Page.GetType(), "validation", "<script language='javascript'>alert('Invalid Username and Password')</script>");
}
}
Left by zakir ughradar on Apr 12, 2012 1:14 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
hi all,
nice coding.
But pls provide with remember me control(check box) coding
Left by sudha s g on Apr 14, 2012 12:00 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
good coding and very helpful
Left by jk on Apr 22, 2012 11:28 PM

# create a registration form about personal details
Requesting Gravatar...
plzz help to it
Left by ramden on May 02, 2012 8:11 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
Here is MySql version
-------------------------------------------
-------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using MySql.Data.MySqlClient;


namespace WebApplication2
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}

public string GetConnectionString()
{
string baglanti_setiri = "Server=localhost;Database=testBase;Uid=root;Pwd=";
return baglanti_setiri;
}

private void ExecuteInsert(string name, string username, string password, string gender, string age, string address)
{
MySqlConnection conn = new MySqlConnection(GetConnectionString());
string sql = "INSERT INTO tblregister (Name, UserName, Password, Gender, Age, Address) VALUES "
+ " (@Name,@UserName,@Password,@Gender,@Age,@Address)";

try
{

MySqlCommand cmd = new MySqlCommand(sql,conn);
MySqlParameter[] param = new MySqlParameter[6];
//param[0] = new SqlParameter("@id", SqlDbType.Int, 20);
param[0] = new MySqlParameter("@Name", MySqlDbType.VarChar, 50);
param[1] = new MySqlParameter("@UserName", MySqlDbType.VarChar, 50);
param[2] = new MySqlParameter("@Password", MySqlDbType.VarChar, 50);
param[3] = new MySqlParameter("@Gender", MySqlDbType.VarChar, 10);
param[4] = new MySqlParameter("@Age", MySqlDbType.Int32);
param[5] = new MySqlParameter("@Address", MySqlDbType.VarChar, 50);

param[0].Value = name;
param[1].Value = username;
param[2].Value = password;
param[3].Value = gender;
param[4].Value = age;
param[5].Value = address;

for (int i = 0; i < param.Length; i++)
{
cmd.Parameters.Add(param[i]);
}

cmd.CommandType = CommandType.Text;
conn.Open();
cmd.ExecuteNonQuery();
}
catch (MySqlException ex)
{
string msg = "Insert Error:";
msg += ex.Message;
throw new Exception(msg);
}
finally
{
conn.Close();
}
}

protected void Button1_Click(object sender, EventArgs e)
{
if (TxtPassword.Text == TxtRePassword.Text)
{
//call the method to execute insert to the database
ExecuteInsert(TxtName.Text,
TxtUserName.Text,
TxtPassword.Text,
DropDownList1.SelectedItem.Text,
TxtAge.Text, TxtAddress.Text);
Response.Write("Record was successfully added!");
ClearControls(Page);
}
else
{
Response.Write("Password did not match");
TxtPassword.Focus();
}
}

public static void ClearControls(Control Parent)
{

if (Parent is TextBox)
{ (Parent as TextBox).Text = string.Empty; }
else
{
foreach (Control c in Parent.Controls)
ClearControls(c);
}
}
}
}
Left by QatiL on May 03, 2012 6:17 PM

# Noob not getting it
Requesting Gravatar...
What do i do with the code thats not HTML??
i cant put it in Default.aspx (thats where i have the html)
Left by Baatus on May 04, 2012 9:26 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
It's perfectly useful.
Thank you so much.
Left by Hadi on May 06, 2012 9:16 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
plz post me web form projects
Left by syed Rehaman on May 10, 2012 11:53 PM

# how to redirect login page to master page?
Requesting Gravatar...
i wnt the code and for the login page and registration provides validation and also redriect to master page
Left by giri on May 17, 2012 7:02 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
This is very helpful, thanks
Left by Claire's Admin on May 23, 2012 3:32 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
THANKS VERY MUCH MY PROJECT IS 20% DONE
Left by Samuel Nana Barimah Kwantwi on May 24, 2012 8:17 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

public partial class Registration : System.Web.UI.Page
{
SqlConnection con = new SqlConnection();

protected void Page_Load(object sender, EventArgs e)
{
con.ConnectionString = "Data Source = NIIT-738042B674; Initial Catalog =rahi; Integrated security = True";
con.Open();


}
protected void btn_sub_Click(object sender, EventArgs e)
{
String str = " insert into Registration Values('"+ txt_uName.Text+"','"+txt_pass.Text+"','"+ddl_prof.SelectedItem.Text+"','"+txt_Name.Text+"','"+rb1_gen.Text+"','"+txt_Dob.Text+"','"+ddl_religion.SelectedItem.Text+"','"+ddl_MT.SelectedItem.Text+"','"+ddl_Country.SelectedItem.Text+"')";
SqlCommand cmd = new SqlCommand(str, con);
cmd.ExecuteNonQuery();
con.Close();
Response.Redirect("Registration.aspx");
}
protected void btn_can_Click(object sender, EventArgs e)
{
Response.Redirect("Registration.aspx");
Left by Anees ahmad on May 26, 2012 1:25 AM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
nice answer
Left by sivaram on Jun 01, 2012 10:20 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
very nice and really helpful article.
Left by nizam on Jun 04, 2012 3:37 AM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
this is nic guys.....so helpfull...
Left by raj on Jun 08, 2012 8:12 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
What you have given is very nice but i am getting some error like 'System.Data.SqlClient.SqlParameter' does not contain a constructor that takes 1 arguments' please help me how to solve it
Left by suvarna on Jun 16, 2012 3:58 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
What you have given is very good but i am getting some error like 'System.Data.SqlClient.SqlParameter' does not contain a constructor that takes 1 arguments' please help me how to solve it
Left by venu on Jun 18, 2012 3:58 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
Error 1 No overload for method 'ExecuteInsert' takes 9 arguments c:\users\mohammedy\documents\visual studio 2010\Projects\student\student\Default.aspx.cs 96 13 student
Left by yazeed on Jun 24, 2012 3:46 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
Very good code, with this exemple I create my first application in ASP.NET C#.
Thanks
Left by Julian Leite on Jul 03, 2012 10:22 AM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
'Button1_Click' is not a member of ASP.default_aspx'.

help !!
Left by AAA on Jul 18, 2012 10:24 AM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
Hi everyone... very nice tutorial... i am also brand new with asp.net... i got the database running and the html part up. I also set the web.config to connect to my db. But now i am trying to connect the dots between executeInsert method and button1_click... where do I put these files? Thanks
Left by JSS on Jul 24, 2012 11:28 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
I figured that one out but now I have problem with connecting to database.
First GetConnectionString() says "unreachable code detected" on the code 'return'.
private string GetConnectionString()
{
throw new NotImplementedException();
return System.Configuration.ConfigurationManager.ConnectionStrings["Applicationservices"].ConnectionString;
}

and 2nd. on
SqlConnection conn = new SqlConnection(GetConnectionString());

The first SqlConnection says "this class cannot be inherited".

I but both these methods on same "default.aspx.cs" file

Left by JSS on Jul 25, 2012 4:15 AM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
It was very helpful but what it i'm just going to use microsoft access insted of sql how can i connect it w/ my asp?
Left by Lana on Jul 28, 2012 3:01 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
hi,this website very useful
Left by ganesh kumbhar on Jul 31, 2012 4:59 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
Hey Guys,
The above code for creating a register page in ASP.NET is very helpful! Does anyone know how to do it, but with using an Access connection? I would appreciate any help on this!
Thank you
Left by TLD on Aug 06, 2012 10:09 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
Its really very useful and awesome tips
Left by vignesh.A on Aug 31, 2012 5:39 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
Thanks for this nice tutorial, but i have a small issue
Am getting an error on this line
"<asp:Button ID="Button1" runat="server" Text="Save" Onclick="Button1_Click" />"

Error reads

Compiler Error Message: BC30456: 'Button1_Click' is not a member of 'ASP.default_aspx'.

please help
Left by Isaac on Sep 04, 2012 3:13 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
nice tips. wish begginners like me would get more help from you.
was really helpful.
the codes above write to a DB. what if one is interested in reading from a DB; incase of report writing and others?
Left by uche on Sep 04, 2012 6:55 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
hi............it beauty for more use my knowledge............
Left by chirag on Sep 09, 2012 6:09 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
hi............it beauty for more use my knowledge............
Left by chirag on Sep 09, 2012 6:09 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
trully nice artical..fully helpfull...keep it up..

Thank you very very much.. :)
Left by Ashok & Nandu on Sep 14, 2012 7:58 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
trully nice artical..fully helpfull...keep it up..

Thank you very very much.. :)

looking forword for same help to new programers..
Left by Ashok on Sep 14, 2012 8:04 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
The tutoria es very good, thanks..

I have an error on this line

"<asp:Button ID="Button1" runat="server" Text="Save" Onclick="Button1_Click" />"

Error reads

Compiler Error Message: BC30456: 'Button1_Click' is not a member of 'ASP.default_aspx'.

please helpme
Left by Alex on Sep 19, 2012 9:27 AM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
This step-by-step guidelines on how to register in ASP.NET are indeed helpful. Thanks!
Left by www.tutorsville.net on Sep 27, 2012 5:44 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
How to asign automatic id for new registration?
Left by sajin on Oct 12, 2012 12:21 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
This code is working fine. But I need to ensure that people cannot register with the same username twice. I can do it by making username column in database unique. But then error will throw out. So how to have this? Also it should display in the webpage that 'This username has already taken. Please try with another one'
Left by Dito on Oct 15, 2012 10:32 AM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
http://bit.ly/UCW2N0 this one is in vb.net
Left by ZIl on Oct 25, 2012 12:46 AM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
simple and humble
Left by abi on Nov 03, 2012 8:14 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
Hai swathi here,
I am new to asp.net,i had done this registration module, evertything is ok but,its showing error at datasource at connection string,as "unrecogonized escape sequence"......tell me what's the error,
Left by Swathi on Dec 19, 2012 6:39 PM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
where the heck do I put the code from Step 4,5,6? in the code behind for Default.aspx??????

Can someone just post the solution/files somewhere?

(I swear... things that are so easy/simple in PHP are nearly impossible in .NET)
Left by Ike on Dec 20, 2012 8:54 AM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
Bem feito, online poquer tudo muito interessante e eu realmente gosto de seu site. O artigo é muito bom. Visite-nos
Left by Art373 on Dec 27, 2012 5:43 AM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
can u plz get me the total working code file plz
Left by jayaram on Jan 06, 2013 12:13 AM

# re: Creating a Simple Registration Form in ASP.NET
Requesting Gravatar...
Hey i was wondering if it was possible to use this code for a mdb database instead of Sql database
Left by Keenan on Jan 24, 2013 12:45 AM

comments powered by Disqus

Copyright © Vincent Maverick Durano | Powered by: GeeksWithBlogs.net | Join free