Reputation: 25944
Is there a way to only load the new or updated (edited) records in a table using Sql in C#? Suppose i have a table which consists of 1000 student records.I want to show this information in a gridview ( this is just an example ) and upon adding or editing new entries,I want the gridview to get updated and show the latest changes to the table.If i go and have a
select *
statement ,This will definitely kill the application performance,So i thought its a good idea to try to add only those new records to the previously loaded records to the gridview. But I'm clueless on the How to do such a task.
Upvotes: 0
Views: 243
Reputation: 62266
There is no other solution then simply architect you database.
Just one of many possible solutions: for every inserted or updated record in database you can have a timestamp
. Having that information in database you can:
a) get the latest, from timestamp
point of view, record in your DataGrid
b) get from darabase all reoirds that have timestamp
bigger then it.
I repeat, this us just one of many possible solutions. What fits your requirements has to be decided by yourself.
Upvotes: 4
Reputation: 14292
The simplest way would be add a new field in the table such as ModifyDate of type datetime, and on insertion and updation of record put the current datetime in these field.
In that case you can select a query on the basis of this field as follows
Select Top 10 * from Table1 OrderBy ModifyDate desc
Upvotes: 3
Reputation: 59016
Create a timestamp column and store the "last updated" date. Within your application, store the last time the data was retrieved from the database. Then, you can select only the records that have changed (or been added) since then.
Upvotes: 3