Deleting data
Glossary Item Box
Examples of using the Delete class to erase data
You can download the package with the configuration web service implementing the cases described below using the following link.
In most cases, the deletion request should contain the Where condition, which specifies which records exactly should be deleted. Otherwise, all records will be deleted.
The example code demonstrates available methods for passing parameters to the query. When developing a project, be aware that parameters originating from the user should never be passed to the Column.Const method, since this can lead to a successful SQL injection attack.
Example 1
public string GetSqlTextExample(string name) { var result = ""; var delete = new Delete(UserConnection) .From("Contact") .Where("Name").IsEqual(Column.Parameter(name)); result = delete.GetSqlText(); return result; }
Example 2
public string DeleteContacts(string name) { var delete = new Delete(UserConnection) .From("Contact") .Where("Name").IsEqual(Column.Parameter(name)); var cnt = delete.Execute(); return $"Contacts with name {name} were deleted. {cnt} rows affected"; }
See also: