0

我无法将字符串格式的变量(从表单上的 DateTime 选择器控件)转换为简单的 Date。

我正在尝试转换,因为我收到以下错误消息:

INVALID_FIELD:\nAND c.Status__c = 'Closed' AND c.Close_Date__c > 2013-07-01T00:00:00Z\n ^\nERROR at Row:1:Column:326\n 字段“Close_Date__c”的过滤条件值必须是日期类型,不应包含在引号中

我试过了:

sQry += " AND c.Close_Date__c > " + DateTime.ParseExact(filterFromDate, "d", CultureInfo.InvariantCulture) + " AND c.Close_Date__c < " + DateTime.ParseExact(filterFromDate, "d", CultureInfo.InvariantCulture);

但它不接受它(编译器无法识别CultureInfo.

请问我哪里错了?

更多信息:对不起,我应该提到我们正在对引用 SalesForce 实例的 SalesForce 对象使用此查询

4

2 回答 2

1

添加 System.Globalization 然后...

var date = DateTime.ParseExact(filterFromDate, "dd", CultureInfo.InvariantCulture);
于 2013-09-18T11:19:16.257 回答
1

更新...

那这个呢(我做了很多假设.....)在哪里

string filterFromDate = "2013-07-01T00:00:00Z";

sQry += " AND c.Close_Date__c > " + DateTime.Parse(filterFromDate).Date.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'sszzzzz") + " AND c.Close_Date__c < " + DateTime.Parse(filterFromDate).Date.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'sszzzzz");

或者使用 SqlParameters 更好

string filterFromDateStr = "2013-07-01T00:00:00Z";

//Just the date since we don't want to use the Time
var filterFromDate = DateTime.Parse(filterFromDateStr ).Date;

sQry += " AND c.Close_Date__c > @filterFromDate AND c.Close_Date__c < @filterFromDate";

IDbCommand cmd = connection.CreateCommand();
cmd.CommandTimeout = connection.ConnectionTimeout;
cmd.CommandText = sQuery;

cmd.Parameters.Add(new SqlParameter("@filterFromDate ",filterFromDate ));

md.Connection = connection;
var reader = cmd.ExecuteReader();

于 2013-09-18T11:34:53.797 回答