Click here to Skip to main content
12,698,330 members (23,026 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# WPF DateTime SQLite
I want to reading a datetime value from a Sqlite database and assign it to datepicker control. Here is my code that i am trying:


string Query = "Select * from Customer_New where Cust_Id='" + val + "' ";

SQLiteCommand createCommand = new SQLiteCommand(Query, sqlitecon);
// createCommand.ExecuteNonQuery();
SQLiteDataReader dr = createCommand.ExecuteReader();
date_open.DisplayDate = dr.GetDateTime(1);
Date_Joining.DisplayDate = dr.GetDateTime(2);
txt_Title.Text = dr.GetString(3);
txt_cardnum.Text =dr.GetString(4);
catch (Exception ex)

The above code is executed on form load event .so when form loads it should load the date value from db table into date picker .but form is opening with Message box that shows exception "specified cast is not valid". Then it fails to load any value from db and if i remove date fields from assigning in while loop then rest of text fields are assigned correctly to form . My db foramt of date is :MM/DD/YYYY and is of type datetime . On debugging by putting break point at "date_open.DisplayDate = dr.GetDateTime(1);" it shows system date and time .My db tables are following sequence: Cust_id | date_open | Date_Joining |..... .Please Help
Posted 9-Oct-13 22:28pm
Pheonyx 10-Oct-13 3:43am
if you step through your code and before either of the dr.GetDateTime lines execute, view the dr.GetDateTime(1) or dr.GetDateTime(2) in the watch window, what values do you get?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170118.1 | Last Updated 10 Oct 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100