foreach loop through database table .net c#

It's been a long day and I seem to have drawn a blank with my current issue. Below is code contained in my HomeController:

 public ActionResult About()
            SqlDataReader rdr; 
            string fileName = "";
            const string connect = @"Server=localhost;Database=Images;user id=user; password=password;";

            using (var conn = new SqlConnection(connect))

                var qry = "SELECT FileName FROM FileStore";
                var cmd = new SqlCommand(qry, conn);
                rdr = cmd.ExecuteReader();

                if (rdr.HasRows)
                    fileName = rdr["FileName"].ToString();

            return View();

I simply want to display a list of the fileNames from the database in a view. I remember how to do this but I'm stuck on how to write the loop statement that will loop through my sql table.

Can someone point me in the right direction please?


if (rdr.HasRows) {
    while (rdr.Read()) {
        fileName = rdr["FileName"].ToString();

Need Your Help

How do I spawn threads on different CPU cores?

c# .net windows multithreading

Let's say I had a program in C# that did something computationally expensive, like encoding a list of WAV files into MP3's. Ordinarily I would encode the files one at a time, but let's say I wanted...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.