Clicking the Remove button in the application triggers the execution of the profileRemoveButton_Click event handler.
Note: This example uses the ingresDeleteCommand6, which was created when the ingresDataAdapter6 was created.
The query is as follows:
DELETE FROM user_profile WHERE up_email = ?
You can write this query using the Query Designer for the IngresCommand by changing the CommandText property, or assign them directly to the IngresCommand CommandText property as a string.
The value selected in the profileEmailComboBox is used to identify the profile record for deletion.
A transaction is defined to allow programmatic transaction control of the deletion. The row is deleted, but the change is not committed until a confirmation is received from the dialogue.
A transaction is defined for the session and assigned to the delete command. A commit or rollback is not performed until the respective method is invoked.
public int ProfileRemove(DataSet profileDataSet, string profileAddr)
{
int rowsDeleted = 0;
IngresParameter email = new IngresParameter("up_email",
IngresType.NChar);
try
{
IngresConnection connection;
IngresTransaction delete;
email.Value = profileAddr;
connection = ingresDataAdapter6.DeleteCommand.Connection;
connection.Open();
delete = connection.BeginTransaction();
ingresDataAdapter6.DeleteCommand.Prepare();
ingresDataAdapter6.DeleteCommand.Parameters.Clear();
ingresDataAdapter6.DeleteCommand.Parameters.Add(email);
rowsDeleted = ingresDataAdapter6.DeleteCommand.ExecuteNonQuery();
DialogResult result = MessageBox.Show("Profile: " + profileAddr,
"Remove profile", MessageBoxButtons.YesNo,
MessageBoxIcon.Warning);
if (result == DialogResult.No)
{
rowsDeleted = 0;
delete.Rollback();
}
else if (result == DialogResult.Yes)
{
delete.Commit();
}
connection.Close();
}
catch (IngresException ex)
{
DialogResult result = DisplayError(ex);
if (result != DialogResult.OK)
{
throw;
}
}
return (rowsDeleted);
}