Adding a counter is the easiest:
var recordCount = 0;
String connectionString = "Data Source=XPSSLOWPC;Initial Catalog=Movies;Integrated Security=True;";
using (SqlConnection connection = new(connectionString))
{
connection.Open();
String sql = "select Title, Year, Format, Length, Video, Audio from Info where Format = 'Ultra HD' order by Title";
using (SqlCommand command = new(sql, connection))
{
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
++recordCount;
MovieInfo movieinfo = new MovieInfo();
{
movieinfo.Title = reader.GetString(0);
movieinfo.Year = reader.GetString(1);
movieinfo.Format = reader.GetString(2);
movieinfo.Length = reader.GetString(3);
movieinfo.Video = reader.GetString(4);
movieinfo.Audio = reader.GetString(5);
};
ListMovies.Add(movieinfo);
}
}
}
}
Note: you could a “select @@rowcount” to the query and it would come in the second result set.