Reputation: 471
I am working on windows application.
In that application, I am saving data in database.
And retrieving data in data grid view.
For that I am using following code :
var expenselist = db.SP_TodaysExpense().Where(a => a.Date <= DateTime.Now.Date).ToList();
DgvTodaysExpense.DataSource = expenselist;
above code shows all the data in database. But, I want to show data that are added only after opening the application.
So how can I do this ?
Thank you in advance.
Upvotes: 2
Views: 250
Reputation: 125277
OP: I want to show data that are added only after opening the application.
Based on your requirement, you need to get start time of your application. Storing start time in settings is pointless (while it will work). There are also better options:
Option 1 - Get start up time of the application using StartTime
of Current Process:
var start = System.Diagnostics.Process.GetCurrentProcess().StartTime;
Option 2 - Store StartTime in a static property of Program
class:
public static DateTime StartTime { get; private set; } /* Usage: Program.StartTime */
[STAThread]
static void Main()
{
StartTime = DateTime.Now;
//...
}
Upvotes: 2
Reputation: 30042
You need to save a Datetime Value in the App Settings (Right click Project => Propeties => Settings ):
Note : Use Scope => User in order to be able to update the value.
Then in Program.cs Main method add:
Properties.Settings.Default.LastOpenedTime = DateTime.Now;
Properties.Settings.Default.Save();
and change your query to:
DateTime queryTime = Properties.Settings.Default.LastOpenedTime ;
var expenselist = db.SP_TodaysExpense().Where(a => a.Date >= queryTime ).ToList();
DgvTodaysExpense.DataSource = expenselist;
For More on App Settings : Read Here
Upvotes: 2