如何最近将数据从sql数据库插入到asp.net webform中 [英] how to get recently insert data from sql database into asp.net webform

查看:70
本文介绍了如何最近将数据从sql数据库插入到asp.net webform中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在数据库中,我有大约100条记录,但最近在过去1周内插入了3条记录。

然后当我运行aspx webform时,我应该得到那些最近插入的那3条记录。

任何人都可以帮助我

In database i have some 100 records but recently 3 records are inserted in past 1 week.
Then when i run the aspx webform i should get those recently inserted those 3 records.
Can anyone help me

推荐答案

您需要在表格中记录一些数据,以便记录插入数据的时间以及以前是否已读取。当您从表中检索记录时,您可以从上次读取的日期/时间检索记录,由其他地方的代码跟踪,或者您可以检索之前使用该标记读取的记录并只检索尚未读取的记录。您必须在您的站点中使用某种机制让用户将您的记录标记为已读,这样您就不会再次检索它们。
You'll need some data in the table to record when the data was inserted and if it was previously "read". When you retrieve the records from the table, you can either retrieve the records from the last date/time that was "read", tracked by your code elsewhere, or you can retrieve records that were "read" before with the flag and just retrieve records that have not been "read". You'll have to have some mechanism in your site to let the user mark thee records "read" so you don't retrieve them again.


您好,



如果你想返回最近插入的记录,那么应该有一个日期过滤器,我假设你正在查看过去1周的最近插入记录。



请参阅以下示例查询相同的

Hi,

If you want to return recently inserted records there should be a date filter, I assume that you are looking recent insert records for past 1week.

Refer below sample query for the same
Declare @tab table
(
    val int,
	insertdate datetime
)

insert into @tab
values(100,'2015-11-09 12:23:30.377'),(101,'2015-11-10 12:23:30.377'),(102,'2015-11-11 12:23:30.377'),
(104,'2015-11-12 12:23:30.377'),(105,'2015-11-13 12:23:30.377'),(106,'2015-11-14 12:23:30.377'),
(107,'2015-11-15 12:23:30.377'),(108,'2015-11-16 12:23:30.377')

select * from @tab
where CONVERT(date, insertdate) >=CONVERT(date, GETDATE()-7)


从your_table orderby中选择* top 3来自ID DESC

此查询将获取您已插入的最后3条记录
Select *top 3 from your_table orderby ID DESC
This query will fetch last 3 records you have inserted


这篇关于如何最近将数据从sql数据库插入到asp.net webform中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆