The values to be added are extracted from the DataGridView row and assigned into a data table cloned from the updateRoute.
// Clone the table structure.
DataTable dataTable = routeDataSet1.Tables["updateRoute"].Clone();
// Create a new row.
DataRow dataRow = dataTable.NewRow();
for (int i = 0, j = 0;
(i < LastDataRow.ItemArray.Length); i += 1)
{
// Populate the update row with values from
// matching columns.
if ((j < dataRow.ItemArray.Length) &&
(dataRow.Table.Columns[j].ColumnName ==
LastDataRow.Table.Columns[i].ColumnName))
{
// Save the query parameters to re-issue
// the query.
if (dataRow.Table.Columns[j].ColumnName.Equals("rt_depart_from"))
{
lastQuery.departingAirport =
LastDataRow.ItemArray[i].ToString();
}
if (dataRow.Table.Columns[j].ColumnName.Equals("rt_arrive_to"))
{
lastQuery.arrivingAirport =
LastDataRow.ItemArray[i].ToString();
}
if (dataRow.Table.Columns[j].ColumnName.Equals("rt_flight_day"))
{
lastQuery.onDays =
LastDataRow.ItemArray[i].ToString();
}
// Copy the value in the equivalent column.
dataRow[j] = LastDataRow.ItemArray[i].ToString();
j += 1;
}
}
// Add the row to the table. Could add more than
// one here and add them all at once or used the
// rows rather than the table.
dataTable.Rows.Add(dataRow);
RouteAdd(dataTable);
To add the row
Call the ingresDataAdapter5.Update method with the data table.
public void RouteAdd(DataTable dataTable)
{
try
{
ingresDataAdapter5.InsertCommand.Parameters.Clear();
ingresDataAdapter5.InsertCommand.Parameters.Add("@rt_airline",
Ingres.Client.IngresType.NChar, "rt_airline");
ingresDataAdapter5.InsertCommand.Parameters.Add("@rt_flight_num",
Ingres.Client.IngresType.Int, "rt_flight_num");
ingresDataAdapter5.InsertCommand.Parameters.Add("@rt_depart_from",
Ingres.Client.IngresType.NChar, "rt_depart_from");
ingresDataAdapter5.InsertCommand.Parameters.Add("@rt_arrive_to",
Ingres.Client.IngresType.NChar, "rt_arrive_to");
ingresDataAdapter5.InsertCommand.Parameters.Add("@rt_depart_at",
Ingres.Client.IngresType.DateTime, "rt_depart_at");
ingresDataAdapter5.InsertCommand.Parameters.Add("@rt_arrive_at",
Ingres.Client.IngresType.DateTime, "rt_arrive_at");
ingresDataAdapter5.InsertCommand.Parameters.Add("@rt_arrive_offset",
Ingres.Client.IngresType.TinyInt, "rt_arrive_offset");
ingresDataAdapter5.InsertCommand.Parameters.Add("@rt_flight_day",
Ingres.Client.IngresType.NChar, "rt_flight_day");
ingresDataAdapter5.Update(dataTable);
}
catch (IngresException ex)
{
DialogResult result = DisplayError(ex);
throw;
}
}