【问题标题】:Query Database from Mobile Service with Respect to Current DateTime根据当前日期时间从移动服务查询数据库
【发布时间】:2016-04-15 05:17:44
【问题描述】:

我正在使用以下代码行从 azure 移动服务成功查询 azure sql 数据库:

var targetUri = new Uri("https://studytoolmobile.azure-mobile.net/tables/TodoItem?$filter=(complete%20eq%20true)");

我想我可以修改它以适应我的特定目标。我的目标是查询数据库以返回 Notification1 列中的值与当前日期时间匹配的记录:

DateTime currentTime = DateTime.Now;
currentTime = currentTime.AddMilliseconds(-currentTime.Millisecond);
string timeString = currentTime.ToString();

var targetUri = new Uri("https://studytoolmobile.azure-mobile.net/tables/TodoItem?$filter=(Notification1%20eq%20" + timeString + ")");

问题是它给了我一个错误:

'The remote server returned an error: (400) Bad Request.'.

这让我相信它是由我正在使用的新 Uri 引起的。

有谁知道完成此任务的正确 uri 是什么?还是我的错误有不同的原因?谢谢。

【问题讨论】:

    标签: c# sql azure uri azure-mobile-services


    【解决方案1】:

    您需要使用正确的 OData DateTime 文字语法。例如:

    $filter=(Notification1 eq datetime'2010-01-25T02:13:40.1374695Z')

    您可以使用currentTime.ToString("o") 从您的DateTime 实例中获取所需的ISO 格式值。

    【讨论】:

    • 谢谢您,先生。你拯救了我的夜晚!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-17
    • 2014-11-02
    • 2011-09-26
    • 1970-01-01
    • 1970-01-01
    • 2011-02-04
    相关资源
    最近更新 更多