First things first;
your code is vulnerable to
SQL Injection!
Never, ever, ever create an SQL query by stringing together a command and user input. The proper way to add user input into a query is via the Command's parameter collection
try
{
sqlitecon.Open();
string Query = "Select * from Customer_New where Cust_Id= ? ";
SQLiteCommand createCommand = new SQLiteCommand(Query, sqlitecon);
createCommand.Parameters.AddWithValue("val", val);
Next thing to talk about is "
My db foramt of date is :MM/DD/YYYY and is of type datetime"; DateTimes are actually numerical values; and what you are seeing is based on either your local system settings or the settings of the displaying application. You may want to actually verify what type this is as SQLite doesn't have a "true" DateTime type.
SQLite - Data Type - Tutorialspoint[
^]
The way that your query looks, it appears that only one record should be returned. If this is the case then you do not need a
WHILE loop
; as only a maximum of 1 row should be returned. Instead you should be using the
HasRows
property (which should be used even if multiple records are returned, wrapping the loop).
I would also be tempted to grab the values from your DataReader into local variables first to make sure you are getting what you think you are getting, and then populate the form controls from those local values. It just may help identify what exactly you got going on as you can see the types/values of those local variables when you hit a breakpoint.
The above 2 paragraphs would give me code looking something like this
if (!dr.HasRows) { throw new Exception("No Rows Returned"); }
else {
var DisplayDateOpen = dr.GetDateTime(1);
var DisplayDateJoin = dr.GetDateTime(2);
var Title = dr.GetString(3);
var CardNum = dr.GetString(4);
date_open.DisplayDate = DisplayDateOpen;
Date_Joining.DisplayDate = DisplayDateJoin;
txt_Title.Text = Title;
txt_cardnum.Text = CardNum;
}
Once you get comfortable with this and know what exactly is going on; you could adjust as needed.