title: Index was outside the bounds of the array shown when date retrieve from database
body: <pre><code>dateTimePicker2.Value = Convert.ToDateTime((sdr[1]),   
                          CultureInfo.GetCultureInfo("hi-IN").DateTimeFormat);
  </code></pre>
  
  <p>I am pulling a date value from a SqlDataReader, but reading it results in an error:</p>
  
  <blockquote>
    <p>Index was outside the bounds of the array</p>
  </blockquote>
  
  <pre><code>cmd = new SqlCommand("Physio_cure_Search", con);
  cmd.CommandType = CommandType.StoredProcedure;   
  cmd.Parameters.Add("@RegisterNo", SqlDbType.VarChar).Value = txtsearch.Text;    
  SqlDataReader sdr = cmd.ExecuteReader();    
  while (sdr.Read())
  {
      txtregistrationno.Text = sdr.GetString(0);
      //giving error on this line:    
      dateTimePicker2.Value = Convert.ToDateTime((sdr[1]), System.Globalization.CultureInfo.GetCultureInfo("hi-IN").DateTimeFormat);        
  }
  </code></pre>
  
  <p>Here <code>sdr</code> is instance of <code>SqlDataReader</code> and sdr[1] is used to retrieve database value.
  How can this be fixed?</p>
  
  <pre><code>ALTER procedure [dbo].[Physio_cure_Search]
  @RegisterNo varchar(500)   
  As
  begin
      select Convert(varchar(100),DateOfBirth,103) as DateOfBirth 
      from Physio_cureTable
  
      select RegisterNo,RegistrationDate,Stimulation,PationName,DateOfBirth,ContactNo,Occupation,Age,
      Sex,Weight,Chief_Complain,Investigation_Result,PastHistoryAny,Physical_Examination,Ref_By_Doctor,Medications,Prognosis,Electro_Therapy,Neuro_Rehabilitation,Ortho_Rehabilitation,Cardio_Pulmonery_Rehabilitation,Sports_Rehabilitation 
  
      from Physio_cureTable where RegisterNo=@RegisterNo and Syncoperation &lt;&gt;'D'
  end
  </code></pre>