Free templates
Meny Search Free templates

DELETE in a MySQL database (C#, VB and ASP.NET) | Free code

Here you can download free code (C# and VB) for the SQL DELETE statement so that you or a user on your website can remove one or more records in a MySQL database.

Code to DELETE in a MySQL database allows you to remove one or more records from a table in accordance with the conditions specified in the WHERE clause in the SQL DELETE statement. If you want to delete data from multiple tables, you can use multiple DELETE statements or make settings in the database so that all related records in other tables to the record that is deleted in a table are also removed (CASCADE).

When tables in a relational database are related to each other with primary keys and foreign keys, this means restrictions (referential integrity) on records that are to be removed from multiple tables according to the default settings for tables. If records must be removed from several tables then you have to first remove records from tables that not have a table that reference to its primary key (table at the bottom of the hierarchy).

In a MySQL database you can set the relationship for a table with a foreign key to "ON DELETE CASCADE" for the foreign key so that a DELETE statement in the primary table deletes any related records in the foreign table without any restrictions.

This code to delete records in a MySQL database is divided into two files, an aspx page with three examples of DELETE situations and a code page (C# or VB) that contains code for the SQL DELETE statements in the three examples. The web page for the web form is not connected to a "MasterPage", a web project should contain a "master page" that is linked to CSS files so that it becomes easy to maintain the web design for the entire website.

Before you can erase data from a database, you must have created a database, tables in the database and a named connection string to the database in the "Web.config" file. In this template we have created a connection string to the MySQL database with the name of "ConnectionString" and this is the connection string that we make a reference to before we execute SQL statements.

The code for DELETE statements is surrounded by a "Try/Catch/Finally" block and this means that any errors in the code are handled by the web application, it is good to avoid to let errors be handled by the web server for a web host for example.

Remember that you in your web hosting account must have made a setting for the correct version of "ASP.NET" on your website (the version listed in the file "Web.config"). We are using Visual Web Developer 2005 (2010) Express Edition for web programming.
Updated: 01-01-2015 | Created by

Download DELETE in a MySQL database (C#, VB and ASP.NET) | Free code ยป

Tags: sql database code