I am creating a desktop application in which I have to query data in SQL Server by providing date and time. Interval is in seconds and every second I run the query again, with the next date.
In this scenario I am getting data from SQL Server and saving date column value on a label, after processing that data, I am running that query again with the date stored on that label and again..
But there's a problem that my SQL Server datetime column is showing as
2016-12-01 18:36:32.000
and when I access that column in my Winform label, it shows as
12/1/2016 6:36 PM
As I have mentioned that I have to consider seconds also, like in SQL Server my query is working fine because I can change minutes easily but when I try to load that same field on label, it is not showing as it is showing in SQL Server.
All I want is to get that column value the same as it is showing in SQL Server.
This is the code I am using to display datetime value on label.
I have selected the column from a simple SQL query like
SELECT [column name]
FROM [table name]
if (dataset.Tables[0].Rows.Count>0)
{
lblDate.Text = dataset.Tables[0].Rows[0]["CHECKTIME"].ToString();
dgv.DataSource = dataset.Tables[0].DefaultView;
}
Screenshots of error
myDate.ToString("yyyy-MM-dd hh:mm:ss.fff");- following your edit, you would specifically uselblDate.Text = dataset.Tables[0].Rows[0]["CHECKTIME"].ToString("yyyy-MM-dd hh:mm:ss.fff");