Practical-22
Perform delete and search operation in Database
In this practical, we will learn how to perform delete and search 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: Create a table in the database
- Open the Server Explorer window in Visual Studio.
- Expand the Data Connections node and locate the "Databasef" file.
- Right-click on the file and select Open.
- In the Database Explorer window, right-click on the Tables node and select Add New Table.
- Design the table by adding columns and specifying their data types.
- Save the table.
Step 4: Perform delete operation
- Open the default.aspx file in the Solution Explorer.
- Switch to the Design view.
- Drag and drop a Button control onto the web form.
- Set the Text property of the button to "Delete".
- Double-click on the button to generate the click event handler in the code-behind file (default.aspx.cs).
- In the click event handler, write the necessary code to delete a record from the database table.
- Use SQL queries or stored procedures to perform the delete operation.
- Save the changes.
Step 5: Perform search operation
- Open the default.aspx file in the Solution Explorer.
- Switch to the Design view.
- Drag and drop a TextBox control and a Button control onto the web form.
- Set the Text property of the button to "Search".
- Double-click on the button to generate the click event handler in the code-behind file (default.aspx.cs).
- In the click event handler, write the necessary code to search for a record in the database table.
- Use SQL queries or stored procedures to perform the search operation.
- Display the search results in a GridView or any other suitable control.
- Save the changes.
That's it! You have successfully performed delete and search operations in a database using ASP.NET.
Make sure to save your changes and submit this practical in your notebook.