Receiving and manipulating data from a query

1

I'd like to know how to manipulate the data of a query . I have a method that performs a Select , and I'm creating a List to store the results, and returning that list. But how can I use this data outside the method?

Follows:

public List<Results> GetInfo(long id)
        {
            var Id = id;
            using (var conn = DatabaseUtil.GetConnection())
            using (var cmd = conn.CreateCommand())
            {
                cmd.CommandText = $@"SELECT
                                            cb.id AS Id,
                                            p.first_name AS FirstName, 
                                            p.last_name AS LastName,  
                                            cb.date AS Date         
                                        FROM
                                            st_compania cb
                                            JOIN st_pessoa p ON (p.id = cb.compania_id)
                                        WHERE
                                            cb.id = @Id

                cmd.Parameters.Add("@Id", SqlDbType.BigInt).Value = Id;

                var resultList = new List<Results>();

                using (var dr = cmd.ExecuteReaderWithRetry(DatabaseUtil.RetryPolicy))
                {
                    while (dr.Read())
                    {
                        resultList.Add(new Results
                        {
                          Id = Convert.ToInt64(dr["Id"]),
                          FirstName = Convert.ToString(dr["FirstName"]),
                          LastName = Convert.ToString(dr["LastName"]),
                          Date = Convert.ToDateTime(dr["Date"])
                        });
                    }
                }
                return resultList;
            }

        }

Well, Select works, but how can I use these results I collected, let's say on a page where I want to display the person's First and Last name and the date in a Label ? I would have to do something like this:

lblResult.Text = $"Nome: {resultList[1]}, Sobrenome: {resultList[2]} com a data de: {resultList[3]}."
    
asked by anonymous 24.12.2018 / 14:07

1 answer

2
var resultList= GetInfo(1)
foreach (var result in resultList)
{
  Console.WriteLine(result.FirstName);
  Console.WriteLine(result.Date);
}
    
24.12.2018 / 16:59