I am creating a web application using c# & sql server as database. I have two columns in database let's say "name" & "insertedTime" where "insertedTime" contain the time when the "name" is inserted. My work is to fetch data for a time period, let's say for last one hour or last two hours. how do I do this? what will be the query? I hope I have made you understand what is my requirement.
我正在使用c#和sql server作为数据库创建一个Web应用程序。我在数据库中有两列,我们说“name”和“insertedTime”,其中“insertedTime”包含插入“name”的时间。我的工作是获取一段时间的数据,比如最后一小时或最近两小时。我该怎么做呢?什么是查询?我希望我已经让你明白我的要求是什么。
1 个解决方案
#1
1
This sounds like homework so instead;
这听起来像家庭作业,所以相反;
In C# use the timespan object to get the time an hour ago.
在C#中使用timespan对象来获取一小时前的时间。
Connect to the database in a number of ways.
以多种方式连接到数据库。
Create the sql in it's hardcoded form and run it to verify you are getting results.
以它的硬编码形式创建sql并运行它以验证您是否获得了结果。
Replace the date/time sql with the string version of the timespan string
将日期/时间sql替换为timepan字符串的字符串版本
re-run the sql.
重新运行sql。
If you have a go for us and post what code you have tried we'll be more inclined to give you better advice and even code.
如果你去找我们并发布你尝试过的代码,我们会更倾向于给你更好的建议甚至是代码。
#1
1
This sounds like homework so instead;
这听起来像家庭作业,所以相反;
In C# use the timespan object to get the time an hour ago.
在C#中使用timespan对象来获取一小时前的时间。
Connect to the database in a number of ways.
以多种方式连接到数据库。
Create the sql in it's hardcoded form and run it to verify you are getting results.
以它的硬编码形式创建sql并运行它以验证您是否获得了结果。
Replace the date/time sql with the string version of the timespan string
将日期/时间sql替换为timepan字符串的字符串版本
re-run the sql.
重新运行sql。
If you have a go for us and post what code you have tried we'll be more inclined to give you better advice and even code.
如果你去找我们并发布你尝试过的代码,我们会更倾向于给你更好的建议甚至是代码。