title: Reading a datetime value from a SQLite database and assigning it to datepicker in C# using WPF
body: <p>I want to read a datetime value from an SQLite database and assign it to a datepicker control.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>try
  {
      sqlitecon.Open();
      string Query = "Select * from Customer_New where Cust_Id='" + val + "'  ";
      SQLiteCommand createCommand = new SQLiteCommand(Query, sqlitecon);
      //  createCommand.ExecuteNonQuery();
      SQLiteDataReader dr = createCommand.ExecuteReader();
      while(dr.Read()){
          date_open.DisplayDate = Convert.ToDateTime(dr.GetString(0));
          Date_Joining.DisplayDate = Convert.ToDateTime(dr.GetString(1));     
          txt_Title.Text = dr.GetString(3);
          txt_cardnum.Text =dr.GetString(4)          
      }                
      sqlitecon.Close();
  }
  catch (Exception ex)
  {
      MessageBox.Show(ex.Message);
  }
  </code></pre>
  
  <p>but it is giving this error: "specified cast is not valid". How can it be done?. </p>