Date Displaying with time in Application
I have a column with a date datatype in my sql-server database and I
insert this into it 1999-12-23. When i run the select query in my database
is shows the date as 1999-12-23 but when i connect the database to my c#
winform application and retrieve the date it displays as 1999-12-23
00:00:00 (i.e it displays date and time).
These are the codes i used
Create Table
CREATE TABLE Users.Personal
(
/*...Other Codes for the table this is the main problem*/
DateofReg date NOT NULL
)
Select query
SELECT * FROM Users.Personal
(This displays the date as 1999-12-23)
Connection to Database
private void RetrievePersonalDetails()
{
SqlConnection myConnection = new SqlConnection("server=AMESINLOLA;" +
"Trusted_Connection=yes;" +
"database=Crm_Db;");
myConnection.Open();
SqlCommand myCommand = myConnection.CreateCommand();
myCommand.CommandText = "SELECT * FROM Users.Personal WHERE
UniqueID='" + uniqueid + "'";
myCommand.CommandType = CommandType.Text;
SqlDataReader myReader = myCommand.ExecuteReader();
if (myReader.Read())
{
//Other codes inserting to textbox but this is the main problem
txtDor.Text = myReader["DateofReg"].ToString();
}
else
{
MessageBox.Show("Empty");
}
myConnection.Close();
myReader.Close();
}
(This displays the date as 1999-12-23 00:00:00)
Why is the date displaying with time in the application but displaying
well in the database and what can i do to display only date?
No comments:
Post a Comment