Why DataReader skip the 1st row?

Winanjaya Amijoyo 0 Reputation points
2024-04-12T14:02:19.3466667+00:00

Hi All,

I use DataReader as below, why the 1st row is skipped?, what I have missed?

using (NpgsqlConnection conn = new NpgsqlConnection(Models.AppSettings.PG_SQL.Connection_String))
{
    try
    {
        string sql = "select c.pid, c.iccid, c.network, c.cdatetime, c.start_datetime, c.network_id from cdrs c " +
            "where TO_CHAR(c.start_datetime, 'YYYY-MM-DD') >= '2024-04-01' " +
            "and " +
            "TO_CHAR(c.start_datetime, 'YYYY-MM-DD') <= '2024-04-12' and iccid='" + __iccid + "' " +
            "order by c.iccid, c.cdatetime"; 
        using (var dr = conn.ExecuteReader(sql, new
        {
        }))
        {
            while (dr.Read())
            {
                long pid = dr.GetInt64(dr.GetOrdinal("pid"));
                // the 1st pid was skipped here!, I double checked          
            }
        }
    }
    catch (Exception e) { Helper.SaveLogAsync("CDR.test: " + e.ToString(), Models.Errs.ErrType.Err); }
    finally { }
}

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,234 questions
{count} votes