What is the best way of concatenating the list produced by the GetWaypoints
method? I'd like to concatenate all of the items under JobWaypoints
and seperate them by a new line.
I cannot seem to figure out the best way of directly accessing the JobWaypoints
item in the waypoints
list I created.
Window.cs
List<JobComponent.JobList> waypoints = JobComponent.GetWaypoints(jobId);
JobComponents.cs
public static List<JobList> GetWaypoints(int jobId)
{
// Get destination
const string query = "SELECT address FROM waypoint " +
"WHERE id NOT IN(" +
"(SELECT MIN(ID) FROM waypoint where booking_id=@id)," +
"(SELECT MAX(ID) FROM waypoint where booking_id=@id)) " +
"AND booking_id=@id";
var jobList = new List<JobList>();
using (var cmd = new MySqlCommand(query, DbObject.Connection))
{
if (DbObject.Connection.State != ConnectionState.Open)
{
DbObject.OpenConnection();
}
cmd.Parameters.AddWithValue(("@id"), jobId);
try
{
using (MySqlDataReader dataReader = cmd.ExecuteReader())
{
while (dataReader.Read())
{
var item = new JobList
{
JobWaypoints = dataReader["address"] + ""
};
jobList.Add(item);
}
dataReader.Close();
DbObject.CloseConnection();
return jobList;
}
}
catch (Exception ex)
{
ErrorHandlingComponent.LogError(ex.ToString());
throw;
}
}
}