So I have a snippet of the code here that works except for one line which is the InsertAt() part. I would like to know if it is possible to copy the last row and insert it as the first. Think of the idea as this. It probably can be done in the SQL alone behind it but this application is designed to work for both a very old database and oracle so until the system migrates entirely it has to be done like this, unfortunately.
Prior
- Shipment Location 1
- Shipment Location 2
- Shipment Location 2
After
- Start Location
- Shipment Location 1
- Shipment Location 2
- Shipment Location 3
- Destination Location
The code snippet:
// Create a DataTable with a list of shipments.
DataTable dt = c.Query(c.qShipments(Row.Cells[0].Value.ToString()));
// Check if there is at least one shipment
if (dt.Rows.Count >= 1)
{
// Add the destination of the shipments
dt.Rows.Add(0, 0, 9999, textBox_CC.Text, textBox_PC.Text, textBox_SL.Text);
// Add the starting location (which is the same as the destination. It has to be at the top of the DataTable
dt.Rows.InsertAt(dt.Rows[dt.Rows.Count - 1], 0); // The code
// Finally calculate and return the object to populate the datagridview with.
dataGridView_CalculatedRoutes.Rows.Add(x.getRoute(dt));
}
tldr;
Issue: Code returns Row belongs to another table.
Question: How to get the last row to be the first aswell?
Edit question: How to get the last row to be both the first and the last row. (Identical rows)
You could create a new
DataTableand import the rows in the order that you want: