Create Registration form using C#
Hello peeps, I assume you’re already using C# in your project but let me do a quick recap.
C# is an object-oriented, component-oriented programming language. C# provides language constructs to directly support these concepts, making C# a natural language in which to create and use software components.
Now let's dive deep 🧐
Open Visual Studio 2010. Go to the File, New, Projects, and under Visual C# selected Windows.
Create a form register.aspx file, where you have to design a form for inserting data into the database. Add the following fields into your form 📝
- Name
- Ext No.
- Std No.
- Address
- Room no.
- Mobile no.
- Designation
- Department
- Password
HTML Source code of the registration form is mentioned below.
Here you can see how your form should look like!!
Now make your form functional by adding the below code in the register.aspx.cs file
Code Explanation 🎯
⮞ The first step is to create variables. It will be used to create the connection string and the connection to the SQL Server database.
⮞ The next step is to create the connection string. The connection string consists of the following parts
localhost — server
The Initial Catalog is used to specify the name of the database
The UserID and Password are the credentials required to connect to the database.
⮞ Next, assign the connecting string to the variable ‘con’. The variable con is of type SqlConnection. This is used to establish a connection to the database.
SqlConnection is a class in ASP.Net, which is used to create a connection to a database.
⮞ Next, insert data in the table using the SQLCommand object.
⮞ Lastly, use the open method of the con variable to open a connection to the database. Display a message to the user that the connection is established then close the connection to the database.
Conclusion
If you have any questions about this tutorial, please let me know in the comments section of this blog post. You can also contact me through Linkedin. I’m happy to assist you 😊!