Casting Ado.net DataReader to IDataRecord giving strange result

后端 未结 2 1016
感情败类
感情败类 2021-01-14 07:55

I have a query that I run against the database, and I can see that there is a record for 31/05/2013. When I run this query from C# with ADO.NET, and then use the following

2条回答
  •  失恋的感觉
    2021-01-14 08:23

    I think that you are missing record in first example because you move reader by one and then cast it.

    Try this change and see if it worked:

    var timeSeries = new List();  
    using (var reader = cmd.ExecuteReader())
    {
        if (reader.HasRows)
        {
            timeSeries = reader.Cast()
                .Select(r => new TimeSeries
                     {
                         MidRate = (double)r["MidRate"],
                         RiskFactorName = (string)r["RiskFactorName"],
                         SeriesDate = (DateTime)r["SeriesDate"]
                     }).ToList();
        }
    }
    

提交回复
热议问题