Practical-21
Perform insert and update operation in Database
In this practical, we will learn how to perform insert and update operations in a database using ASP.NET.
Step 1: Create a new ASP.NET Web Application project
- Open Visual Studio and create a new ASP.NET Web Application project.
- Choose the Empty template and click OK.
Step 2: Add a SQL Server Database to the project
- Right-click on the project in the Solution Explorer and select Add -> New Item.
- Choose the SQL Server Database template and click Add.
- Name the database file as "Databasef" and click OK.
- The database file will be added to the project.
Step 3: Design the web form
- Open the default.aspx file in the Solution Explorer.
- Switch to the Design view.
- Design the layout of the web form by adding HTML elements, CSS styles, and form controls such as textboxes, buttons, etc.
Step 4: Configure the database connection
- In the code-behind file (default.aspx.cs), write the necessary code to establish a connection to the database.
- Use the SqlConnection class to create a connection object and set the connection string to the database file.
Step 5: Perform insert operation
- Write the necessary code to insert data into the database.
- Use the SqlCommand class to execute an INSERT statement.
- Retrieve the values from the form controls and pass them as parameters to the INSERT statement.
Step 6: Perform update operation
- Write the necessary code to update data in the database.
- Use the SqlCommand class to execute an UPDATE statement.
- Retrieve the values from the form controls and pass them as parameters to the UPDATE statement.
Step 7: Run the application
- Press F5 or click the Start Debugging button to run the application.
- Fill in the form with the required data and click the Insert or Update button.
- The data will be inserted or updated in the database.
That's it! You have successfully performed insert and update operations in a database using ASP.NET.
Make sure to save your changes and submit this practical in your notebook.