title: String was not recognized as a valid DateTime couldn't store in data column in c#.net
body: <p>I have defined a datatable in formload in c#.net as below</p>
  
  <pre><code>    DataTable dtreadd = new DataTable();
      dtreadd.Columns.Add("IDP");
      dtreadd.Columns.Add("date",typeof(DateTime));
      dtreadd.Columns.Add("day");
      dtreadd.Columns.Add("nobatkari");
      dtreadd.Columns.Add("code");
  </code></pre>
  
  <p>So I read some string from a file into this datatable</p>
  
  <pre><code> void ReadToTable()
      {
          try
          {
              dtreadd.Clear();
              if (dir.Trim() != "")
              {
                  c = 0;
  
                  dtreadd.Clear();
                  ArrayList arr = new ArrayList();
                  PersianCalendar persCal = new PersianCalendar();
                  SqlConnection sqlconn = new SqlConnection(DBsetting.Connstring);
                  sqlconn.Open();
                  foreach (string line in File.ReadAllLines(dir.Trim()))
                  {
                      if (!string.IsNullOrEmpty(line.Trim()))
                      {
                          c++;
                          l = line.Trim().Split('\t');
                          l[0] = l[0].Trim();
                          l[1] = l[1].Trim();
                          l[2] = l[2].Trim();
                          l[3] = l[3].Trim();
                          if (arrIDP.Contains(l[0]))
                          {
                              if (!string.IsNullOrEmpty(l[0]) &amp;&amp; l[3] == "1" || l[3] == "0" || l[3] == "7")
                              {
                                  dtreadd.Rows.Add(l[0], l[1], GetDayOfWeek(GetPerDate(l[1])), "",l[3]);
                              }
  
                          }
                      }
                  }
  
                  using (sqlconn)
                  {
                      SqlCommand cmd = new SqlCommand("InsertTaradodReadd", sqlconn);
                      cmd.CommandType = CommandType.StoredProcedure;
                      SqlParameter dtparam =cmd.Parameters.AddWithValue("@INFO_ARRAY", dtreadd);
                      dtparam.SqlDbType = SqlDbType.Structured;
                      cmd.ExecuteNonQuery();
                      RefGrid();
                  }
              }
          }
          catch (Exception ex)
          {     
                  MessageBox.Show(ex.Message);   
          }
          finally
          {
  
          }
      }
  </code></pre>
  
  <p>Records in file is Below</p>
  
  <pre><code>  1)  1 2017-04-09 15:33:39 1   0   1   0        
    2)  1 2017-07-31 08:08:24 1   0   1   0
    3)  4 2017-07-31 08:13:39 1   0   1   0
    4) 2  2017-07-31 08:18:54 1   0   1   0
    5)  4 2017-07-31 13:10:10 1   0   1   0
    6) 2  2017-07-31 14:08:11 1   0   1   0
    7) 1  2017-07-31 17:03:36 1   0   1   0
  </code></pre>
  
  <p>For first record it works ok but for second one  2)  1  2017-07-31 08:08:24 1   0   1   0 it raises an error 
  error is 'String was not recognized as a valid DateTime couldn't store &lt;    2017-07-31 08:08:24> in data column expected type is Datatime.'
  when I see the records I notice that evry things are ok and records are fine but I dont know why there is an error for only this record</p>
  
  <p>@INFO_ARRAY is defined below in sqlserver</p>
  
  <pre><code>USE [HoghooghDastmozd]
  GO
  
  /****** Object:  UserDefinedTableType [dbo].[ReadArrayyy]    Script Date: 01/08/1396 12:26:34 ب.ظ ******/
  DROP TYPE [dbo].[ReadArrayyy]
  GO
  
  /****** Object:  UserDefinedTableType [dbo].[ReadArrayyy]    Script Date: 01/08/1396 12:26:34 ب.ظ ******/
  CREATE TYPE [dbo].[ReadArrayyy] AS TABLE(
      [IDP] [int] NULL,
      [date] [datetime] NULL,
      [day] [nvarchar](max) NULL,
      [nobatkari] [nvarchar](max) NULL,
      [code] [nvarchar](max) NULL
  )
  GO
  
  
  DateTime GetPerDate(string dt1)
  {
      string[] a = dt1.Split(' ');
      string[] ss = a[0].Split('/','-');
      string[] hh = a[1].Split(':');
      string year = ss[2];
      string month = ss[1];
      string day = ss[0];
      string hour = hh[0];
      string min = hh[1];
      string sec = hh[2];
      DateTime dd = new DateTime(int.Parse(year), int.Parse(month), int.Parse(day), int.Parse(hour), int.Parse(min), int.Parse(sec), new PersianCalendar());
  
      return dd;//string.Format("{0}/{1}/{2} {3}:{4}:{5}", year, month, day, hour, min, sec);
  }
  </code></pre>