从关于当前日期时间的移动服务查询数据库
Query Database from Mobile Service with Respect to Current DateTime
我正在使用以下代码行从 azure 移动服务成功查询 azure sql 数据库:
var targetUri = new Uri("https://studytoolmobile.azure-mobile.net/tables/TodoItem?$filter=(complete%20eq%20true)");
我想我可以修改它以适合我的特定 objective。我的objective是查询数据库returnNotification1列中的值与当前Datetime相匹配的记录:
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 是什么?还是我的错误有其他原因?谢谢。
您需要使用正确的 OData DateTime 文字语法。例如:
$filter=(Notification1 eq datetime'2010-01-25T02:13:40.1374695Z')
您可以使用 currentTime.ToString("o")
从您的 DateTime
实例中获取所需的 ISO 格式值。
我正在使用以下代码行从 azure 移动服务成功查询 azure sql 数据库:
var targetUri = new Uri("https://studytoolmobile.azure-mobile.net/tables/TodoItem?$filter=(complete%20eq%20true)");
我想我可以修改它以适合我的特定 objective。我的objective是查询数据库returnNotification1列中的值与当前Datetime相匹配的记录:
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 是什么?还是我的错误有其他原因?谢谢。
您需要使用正确的 OData DateTime 文字语法。例如:
$filter=(Notification1 eq datetime'2010-01-25T02:13:40.1374695Z')
您可以使用 currentTime.ToString("o")
从您的 DateTime
实例中获取所需的 ISO 格式值。