Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 每2分钟从SQL Server检索一次数据_Asp.net_Sql Server 2008_Vb.net 2010 - Fatal编程技术网

Asp.net 每2分钟从SQL Server检索一次数据

Asp.net 每2分钟从SQL Server检索一次数据,asp.net,sql-server-2008,vb.net-2010,Asp.net,Sql Server 2008,Vb.net 2010,我正在做一个关于水传感器测量的图表。每分钟进行3次测量并存储在“传感器”表中 出于我的目的,我每隔2分钟需要数据。也就是说,我将获得5个读数(总共15行),记录10分钟的数据 以下是一个例子: RecordDate Depth ----------------------------------- 2016-01-01 07:01:00 112 2016-01-01 07:01:00 116 2016-01-01 07:01:00

我正在做一个关于水传感器测量的图表。每分钟进行3次测量并存储在“传感器”表中

出于我的目的,我每隔2分钟需要数据。也就是说,我将获得5个读数(总共15行),记录10分钟的数据

以下是一个例子:

RecordDate                 Depth
-----------------------------------
2016-01-01  07:01:00        112
2016-01-01  07:01:00        116
2016-01-01  07:01:00        108
2016-01-01  07:00:00        106
2016-01-01  07:00:00        102
2016-01-01  07:00:00        103
2016-01-01  06:59:00        111
2016-01-01  06:59:00        110
2016-01-01  06:59:00        109
2016-01-01  06:58:00        108
2016-01-01  06:58:00        107
2016-01-01  06:58:00        106
2016-01-01  06:57:00        109
2016-01-01  06:57:00        104
2016-01-01  06:57:00        105
2016-01-01  06:56:00        112
2016-01-01  06:56:00        114
2016-01-01  06:56:00        115
2016-01-01  06:55:00        102
2016-01-01  06:55:00        104
2016-01-01  06:55:00        105
2016-01-01  06:54:00        108
2016-01-01  06:54:00        109
2016-01-01  06:54:00        112
2016-01-01  06:53:00        113
2016-01-01  06:53:00        115
2016-01-01  06:53:00        117
2016-01-01  06:52:00        105
2016-01-01  06:52:00        109
2016-01-01  06:52:00        112 
预期结果:

2016-01-01  07:01:00        112
2016-01-01  07:01:00        116
2016-01-01  07:01:00        108
2016-01-01  06:59:00        111
2016-01-01  06:59:00        110
2016-01-01  06:59:00        109
2016-01-01  06:57:00        109
2016-01-01  06:57:00        104
2016-01-01  06:57:00        105
2016-01-01  06:55:00        102
2016-01-01  06:55:00        104
2016-01-01  06:55:00        105
2016-01-01  06:53:00        113
2016-01-01  06:53:00        115
2016-01-01  06:53:00        117
获取10分钟记录的我的SQL查询:

Declare @LastTime datetime

select top 1 @LastTime = RecordDate  
from Sensor 
order by RecordDate desc

select * 
from Sensor 
where datediff(n, RecordDate, @LastTime) > 10
那么,如何使用SQL每2分钟获取一次数据呢


或者,如果不容易,在VB.net中过滤数据集可以吗。

如果您希望每隔x个时间段在.net应用程序中获取数据,那么您应该利用它来帮助您在x个时间段获取数据,例如,来自MSDN的代码

    private static System.Timers.Timer aTimer;

   public static void Main()
   {
      SetTimer();

      Console.WriteLine("\nPress the Enter key to exit the application...\n");
      Console.WriteLine("The application started at {0:HH:mm:ss.fff}", DateTime.Now);
      Console.ReadLine();
      aTimer.Stop();
      aTimer.Dispose();

      Console.WriteLine("Terminating the application...");
   }

   private static void SetTimer()
   {
        // Create a timer with a two second interval.
        aTimer = new System.Timers.Timer(2000);
        // Hook up the Elapsed event for the timer. 
        aTimer.Elapsed += OnTimedEvent;
        aTimer.AutoReset = true;
        aTimer.Enabled = true;
    }

    private static void OnTimedEvent(Object source, ElapsedEventArgs e)
    {
        Console.WriteLine("The Elapsed event was raised at {0:HH:mm:ss.fff}",
                          e.SignalTime);
    }

代码是C语言的,但是你可以转换成Vb.net,

你到底想做什么?您是否希望SQL或.NET每X分钟将数据推送到某个客户机?在SQL store_proc中这样做将非常好。但如果这样做很困难,我可以在.net代码中返回数据集和筛选条件。谢谢,这并不能回答问题。