Reputation: 1
i am creating an Application in which i want to get only new data from database, suppose i have two records in database table and i select that data in my gridview, then next time when i load data from that table i don't want that previous 2 rows in my grid, i just want new rows if available in database table.
WHAT I HAVE DONE: I have loaded my database table in gridview and counted rows of that grid. then store rows in int variable and next time when i load grid, i again count rows in grid and if there is new row in grid, i transfer these new rows in to new datatable and then assign them to the new grid view. in this method i am confused because this works for if only 1 row is newly added since the data is previously loaded.
WHAT I WANT: i want best method to load only the new record in my database so that the previous data will not displayed and processed again. please help me !
this is the sample code i am using to load data in first dataGridView
using (var con = new SqlConnection(ConStr))
{
string query = "SELECT * FROM CHECKINOUT";
using (var cmd = new SqlCommand(query, con))
{
con.Open();
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0].DefaultView;
}
}
this is the screenshot of table from which i am selecting data. http://imgur.com/a/eIaQ6
Upvotes: 0
Views: 803
Reputation: 166
I can't comment so I'll try posting my suggestions or maybe my answer here.
First of all, Try to fix your Select Query
How can you select the newest data if you use Select *
?
Second From the answer of Satish
Better to add new column like DateInserted
to have a identifier
or clue
for all data from your database.
And Lastly, If you can't modify your database design, then try creating a new table that can relate
or link
the data of your database and insert your identifier there, like the DateInserted
.
P.S Try Satish
answer. It is more easier.
Upvotes: 0
Reputation: 56
Add column InsertDate to your table. Maintain lastDataQueriedDate in your code.. Compare these two dates in your query.
Upvotes: 2