ASP.NET - How get the count of latest inserted records

Asked By Sreelakshmi on 03-May-12 05:28 AM
My requirement get the count of the records inserted in to the table in regular intervals.I am displaying the table in the grid view. I mean to say I need the count of the latest records inserted in some time intervals.. And will display the count as you have ___ unread messages. As we get in the inbox of yahoo ....Or gmail... How to get the count of the inserted records in particular intervals of time.
kalpana aparnathi replied to Sreelakshmi on 03-May-12 05:30 AM

Either use ExecuteScalar(), since your code returns a single value, or if you wish to use the ExecuteReader/ReturnValue, then you need to use "@Count" .

Venkat K replied to Sreelakshmi on 03-May-12 05:41 AM
First Question:
Is there any column/field which used to identify whether it has already displayed in UI previously or inserted newly after the previous fetch?

If not, I suggest you to keep a column which identify above both scenarios, the you can easily get the count by below query:

SELECT Count(1) FROM tblName WHERE <<FieldName>> > <<Previousfetchtime>>

dipa ahuja replied to Sreelakshmi on 03-May-12 05:51 AM
For than you have to and a date or time field. Or you can add a status table which can be increase based on the value of the inserted records.

For ex whenever u add new field , change the count ++
Sreelakshmi replied to dipa ahuja on 03-May-12 07:35 AM
Thank for ur reply.Whenever a complaint is raised, the complaint details will be inserted to the complaints table and a message related to the complaint  will be inserted into the messages_Log table which has the column names as SerialNo,Type,Message,Time. Now I display this table in the gridview in my UI with the orderby time. Here is my Sql Statement.SELECT [Type], [Message], [Time] FROM [Messages_Log] ORDER BY [Time] DESC. Now I need to display the count of the inserted records in every 1 hour time .How to write the query for that...This requirement is similar to the inbox in gmail or yahoo...!
I am stuck with this requirement since 1 month Please help me put to solve this issue........!