title: C# Load a date from a string into a datetimepicker
body: <p>I'm trying to update an old c# program that I inherited along the way.  Not big changes, just adding some new fields etc.  I'm using Visual Studio 2008.</p>
  
  <p>Specifically I'm trying to read a date time from an SQL Table and insert it into a DateTimePicker so the user can read / modify it on the screen.</p>
  
  <p>I have tried a few different ways to do this but the code below seems like the most sensible.</p>
  
  <p>I have read the date time string into a datetime variable from my SQL database.  </p>
  
  <p>I can display the value in a message box no problem but when I try and load it into the dateTimePicker control I get an exception.  </p>
  
  <p>The date displayed in the message box looks like this. 24/06/2015 12:00:00 AM 
  (Australian Date format is correct and I don't care what the time is)</p>
  
  <p>"Object Reference not set to an instance of an object"
  _COMPlusExceptionCode = -532459699</p>
  
  <pre><code>while (sqlDR.Read())
  {
      this.textBoxFixedAmountStreetNumber.Text = sqlDR["lStreetNumber"].ToString() + sqlDR["sStreetNumberSuffix"].ToString();
      this.textBoxFixedAmountStreetName.Text = sqlDR["sStreet"].ToString();
      this.textBoxFixedAmountSuburb.Text = sqlDR["sTown"].ToString();
      DateTime dateString = Convert.ToDateTime(sqlDR["dFixedAmountEndDate"].ToString());
      MessageBox.Show("dFixedAmountEndDate=" + dateString, "Debug", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
      this.dateTimePickerFixedAmountEndDate.Value = dateString;
  }
  </code></pre>
  
  <p>I'm probably the worlds oldest newbie because I do mostly sysadmin and never get to concentrate on a single programing language. :)</p>
  
  <p>Any ideas on what I'm doing wrong is much appreciated.</p>
  
  <p>Thanks
  David</p>