The result table returned by executing a search can be used for removing values in the Ingres base table. The values that qualify the row for deletion are taken from the DataGridView.
Note: This example uses the ingresDeleteCommand5, which was created when the ingresDataAdapter5 was added.
The query is as follows:
DELETE FROM route WHERE rt_airline = ? and rt_flight_num = ? and rt_flight_day = ?
You can write these queries using the Query Designer for the IngresCommand by changing the CommandText property, or assign them directly to the IngresCommand CommandText property as a string.
Transaction control is shown in this example to allow user confirmation of the deletion.
A transaction is defined for the session and assigned to the command, indicating that the transaction should be controlled using a programmatic commit or rollback.
public int RouteDelete(DataGridViewRow row)
{
int deleted = 0;
IngresParameter airline = new IngresParameter("rt_airline",
IngresType.NChar);
IngresParameter flight = new IngresParameter("rt_flight_num",
IngresType.Int);
IngresParameter flight_day = new IngresParameter("rt_flight_day",
IngresType.NChar);
try
{
IngresTransaction delTxn;
IngresCommand delCommand = ingresDataAdapter5.DeleteCommand;
airline.Value = row.Cells[0].Value;
flight.Value = row.Cells[2].Value;
flight_day.Value = row.Cells[8].Value;
delCommand.Connection.Open();
delTxn = delCommand.Connection.BeginTransaction();
delCommand.Transaction = delTxn;
delCommand.Prepare();
delCommand.Parameters.Clear();
delCommand.Parameters.Add(airline);
delCommand.Parameters.Add(flight);
delCommand.Parameters.Add(flight_day);
deleted = delCommand.ExecuteNonQuery();
DialogResult result = MessageBox.Show(
String.Format(
rm.GetString("RouteDeleteConfirm"),
airline.Value.ToString(),
flight.Value.ToString(),
row.Cells[3].Value,
row.Cells[4].Value,
row.Cells[8].Value),
rm.GetString("RouteDeleteCaption"),
MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (result == DialogResult.No)
{
deleted = 0;
delTxn.Rollback();
}
else if (result == DialogResult.Yes)
{
delTxn.Commit();
}
delCommand.Connection.Close();
}
catch (IngresException ex)
{
DialogResult result = DisplayError(ex);
throw;
}
return (deleted);
}