title: ASP.NET MVC "System.IndexOutOfRangeException: There is no row at position 0." when trying to get data from the table
body: <pre><code>namespace PayrollSystem.Models
  {
      public class FormAddEmployee
      {
          public string FirstName { set; get; }
          public string LastName { set; get; }
          public decimal PayRate { set; get; }
          public DateTime StartDate { set; get; }
          public DateTime EndDate { set; get; }
  
          private string m_connectionString;
  
          public void Connect(string server, string database)
          {
              m_connectionString = string.Format("Data Source ='{0}'; Initial Catalog = {1}; Integrated Security=SSPI", server, database);
          }
  
          public void SaveEmployee()
          {
              var commandText = string.Format("INSERT INTO Personnel (FirstName, LastName, PayRate, StartDate, EndDate) VALUES ('{0}', '{1}', {2}, '{3}', '{4}')", FirstName, LastName, PayRate, StartDate, EndDate);
  
              SQLDataWriter(commandText);
          }
  
  
  
          public void GetEmployeeByLastName(string lastName)
          {
              var commandText = string.Format("SELECT FirstName, LastName, PayRate, StartDate, EndDate FROM Personnel WHERE LastName = '{0}'", LastName);
  
              var retValue = SQLDataReader(commandText);
              var rec = retValue.Rows[0];
              FirstName = rec.ItemArray[0].ToString();
              LastName = rec.ItemArray[1].ToString();
              PayRate = Convert.ToDecimal(rec.ItemArray[2].ToString());
              StartDate = Convert.ToDateTime(rec.ItemArray[3].ToString());
              EndDate = Convert.ToDateTime(rec.ItemArray[4].ToString());
  
          }
  
          public DataTable SQLDataReader(string sqlCmd)
          {
              var dataTable = new DataTable();
              using (var con = new SqlConnection(m_connectionString))
              {
                  using (var cmd = new SqlCommand(sqlCmd, con) { CommandTimeout = 500 })
                  {
                      var sqlAdapter = new SqlDataAdapter(cmd);
                      sqlAdapter.Fill(dataTable);
                  }
              }
  
              return dataTable;
  
          }
  
          public void SQLDataWriter(string sqlCmd)
          {
              using (var con = new SqlConnection(m_connectionString))
              {
                  con.Open();
                  try
                  {
                      using (var command = new SqlCommand(sqlCmd, con))
                      {
                          command.ExecuteNonQuery();
                      }
                  }
                  catch (Exception ex)
                  {
                      Console.WriteLine(ex);
                  }
              }
          }
  
  
  
      }
  
  }
  </code></pre>