Skip to main content

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

  1. Open Visual Studio and create a new ASP.NET Web Application project.
  2. Choose the Empty template and click OK.

Step 2: Add a SQL Server Database to the project

  1. Right-click on the project in the Solution Explorer and select Add -> New Item.
  2. Choose the SQL Server Database template and click Add.
  3. Name the database file as "Databasef" and click OK.
  4. The database file will be added to the project.

Step 3: Create a table in the database

  1. Open the Server Explorer window in Visual Studio.
  2. Expand the Data Connections node and locate the "Databasef" file.
  3. Right-click on the file and select Open.
  4. In the Database Explorer window, right-click on the Tables node and select Add New Table.
  5. Design the table by adding columns and specifying their data types.
  6. Save the table.

Step 4: Perform delete operation

  1. Open the default.aspx file in the Solution Explorer.
  2. Switch to the Design view.
  3. Drag and drop a Button control onto the web form.
  4. Set the Text property of the button to "Delete".
  5. Double-click on the button to generate the click event handler in the code-behind file (default.aspx.cs).
  6. In the click event handler, write the necessary code to delete a record from the database table.
  7. Use SQL queries or stored procedures to perform the delete operation.
  8. Save the changes.

Step 5: Perform search operation

  1. Open the default.aspx file in the Solution Explorer.
  2. Switch to the Design view.
  3. Drag and drop a TextBox control and a Button control onto the web form.
  4. Set the Text property of the button to "Search".
  5. Double-click on the button to generate the click event handler in the code-behind file (default.aspx.cs).
  6. In the click event handler, write the necessary code to search for a record in the database table.
  7. Use SQL queries or stored procedures to perform the search operation.
  8. Display the search results in a GridView or any other suitable control.
  9. 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.