'sql(dr) is sending a missing result

I transfer the data I have taken from sql to the list, but it sends 1 missing data every time, the sql command works without any problems. works incorrectly in c# If there are 10 data in sql, it pulls 9 of them.

SqlCommand komut = new SqlCommand("EXEC AnalysisUnitCorrect ", Datacon.baglanti());
        SqlDataReader dr = komut.ExecuteReader();
        if (dr.Read())
        {
            while (dr.Read())
            {
                Analysis s = new Analysis();
                s.UnitName = Convert.ToString(dr[0]);
                s.Correct = Convert.ToInt16(dr[1]);
                AnalysisCorrect.Add(s);
            }

            Datacon.baglanti().Close();
        }
        else
        {
            Datacon.baglanti().Close();
        }


Solution 1:[1]

The if (dr.Read()) line is the problem. Calling "Read()" advances to the next record.

You can simplify this and just remove the if statement and leave the while loop.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 David