title: SQL error converting data type datetime to smalldatetime?
body: <p>In my SQL stored procedure:</p>
  
  <pre><code>@StartDate as smalldatetime,
  @EndDate as smalldatetime
  </code></pre>
  
  <p>In my C# code:</p>
  
  <pre><code>StartDate = new DateTime(1901,01,01,00,00,00);
  EndDate = new DateTime(2200,01,01,00,00,00);
  
  var StartDate2 = StartDate.ToString("dd/MM/yyyy HH:mm:ss");
  StartDate2 = DateTime.ParseExact(StartDate2, "dd/MM/yyyy HH:mm:ss", CultureInfo.InvariantCulture).ToString("dd/MM/yyyy HH:mm:ss");
  StartDate = Convert.ToDateTime(StartDate2);
  
  var EndDate2 = EndDate.ToString("dd/MM/yyyy HH:mm:ss");
  EndDate2 = DateTime.ParseExact(EndDate2, "dd/MM/yyyy HH:mm:ss", CultureInfo.InvariantCulture).ToString("dd/MM/yyyy HH:mm:ss");
  EndDate = Convert.ToDateTime(EndDate2);
  </code></pre>
  
  <p>The column is as a smalldatetime type in the db. I'm going round in the circles with this! whats the correct way to parse my Dates to the correct format for querying in the db?</p>
  
  <p>UPDATE:
  Changed code to this and worked fine.</p>
  
  <pre><code>SqlParameter parameter = daHoliday.SelectCommand.Parameters.Add("@StartDate", System.Data.SqlDbType.SmallDateTime);
  SqlParameter parameter2 = daHoliday.SelectCommand.Parameters.Add("@EndDate", System.Data.SqlDbType.SmallDateTime);
  parameter.Value = StartDate;
  parameter2.Value = EndDate;
  </code></pre>