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();
}
CodePudding user response:
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.