我试图将今天的日期作为整数返回。我试图将它作为字符串返回,它工作正常。但是如何将其作为整数返回?
public string ConvertInvoiceDate()
{
return DateTime.Today.ToString("yyyyMMdd");
}
整数应与yyyyMMdd的格式相同。返回类型是字符串,因为我正在尝试使用字符串。现在我不确定我是否必须返回long / double。使用BizTalk我试图将a值插入Oracle DB中的字段,其类型为Numeric。当我尝试以字符串形式返回时,它会将错误抛出为The value for field "INVOICE_DTE" is invalid. ---> System.FormatException: The string '20170626' is not a valid AllXsd value.
DB中字段的详细信息在
之下完整的错误消息是
A message sent to adapter "WCF-Custom" on send port "WcfSendPort_OracleDBBinding_Table_MACINVOICE_Custom" with URI "oracledb://xxxxx/" is suspended.
Error details: Microsoft.ServiceModel.Channels.Common.XmlReaderParsingException: The value for field "INVOICE_DTE" is invalid. ---> System.FormatException: The string '20170626' is not a valid AllXsd value.
at System.Xml.Schema.XsdDateTime..ctor(String text, XsdDateTimeFlags kinds)
at System.Xml.XmlConvert.ToDateTime(String s, XmlDateTimeSerializationMode dateTimeOption)
at Microsoft.Adapters.OracleCommon.OracleCommonMetadataUtils.ConvertXmlToLob(String text, XmlTypeCode xmlTypeCode, QualifiedType qualifiedType, String fieldName)
--- End of inner exception stack trace ---
Server stack trace:
at System.Runtime.AsyncResult.End[TAsyncResult](IAsyncResult result)
at System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.End(SendAsyncResult result)
at System.ServiceModel.Channels.ServiceChannel.EndCall(String action, Object[] outs, IAsyncResult result)
at System.ServiceModel.Channels.ServiceChannel.EndRequest(IAsyncResult result)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at System.ServiceModel.Channels.IRequestChannel.EndRequest(IAsyncResult result)
at Microsoft.BizTalk.Adapter.Wcf.Runtime.WcfClient`2.RequestCallback(IAsyncResult result)
MessageId: {449B56A2-B053-47A4-826A-400B97CFB9A1}
InstanceID: {DEA7CAA7-D589-4A4E-81A0-A2C6A961D340}
答案 0 :(得分:1)
在返回之前将它们转换为整数,如下所示:
public int ConvertInvoiceDate()
{
return int.Parse(DateTime.Today.ToString("yyyyMMdd"));
}
答案 1 :(得分:0)
正如Panagiotis Kanavos在评论中所说,XML字段可能被定义为使用ISO8601格式的xsd :: datetime,即2017-06-23T13:14:15Z
要实现这一目标,您可以执行以下操作,或者更简单地将datetime functoid连接到地图中的节点。
public string ConvertInvoiceDate()
{
return DateTime.Today.ToString("o");
}
答案 2 :(得分:0)
再试一次
int.Parse(DateTime.Today.ToShortDateString().Replace("-",""))
答案 3 :(得分:-1)
答案 4 :(得分:-1)
如果您正在寻找DateTime对象的数值,则有一个属性Ticks,但它是长类型,而不是int。
https://msdn.microsoft.com/ru-ru/library/system.datetime.ticks(v=vs.110).aspx
答案 5 :(得分:-1)
Downvote完全错了!本答案基于完全不同的问题的先前版本
HOLD ON!
不要使用字符串或整数。您需要使用TryParseExact()返回DateTime。