2017-04-06 7 views
0

私はpsqlデータベースからデータを取り出し、BizTalkを使用してSQL Serverデータベースに挿入しようとしています。 6/30/2016 12:00:00 AMSQL ServerのDateTimeoffsetに文字列を変換します

私はタイプdatetimeoffsetDateCreatedと呼ばれるSQL Serverの列にそのデータを挿入したいのような時間帯でタイプTimeStampcreateddateと呼ばPSQLの列があります。 ParseExactについては

String was not recognized as a valid DateTime.

Exception type: FormatException
Source: mscorlib
Target Site: System.DateTime ParseExact(System.String, System.String, System.Globalization.DateTimeFormatInfo, System.Globalization.DateTimeStyles)

The following is a stack trace that identifies the location where the exception occurred

at System.DateTimeParse.ParseExact(String s, String format, DateTimeFormatInfo dtfi, DateTimeStyles style)
at System.Xml.Xsl.CompiledQuery.Script1.ConvertDateCreated(String dateCreated)
at (XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime, XPathNavigator {urn:schemas-microsoft-com:xslt-debug}current)
at (XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime, XPathNavigator {urn:schemas-microsoft-com:xslt-debug}current)
at Root(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
at Execute(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlSequenceWriter results)
at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter writer)
at System.Xml.Xsl.XslCompiledTransform.Transform(IXPathNavigable input, XsltArgumentList arguments, XmlWriter results, XmlResolver documentResolver)

+0

オリジナルのデータベースから返される日付文字列の例がありますか? – PaulF

+0

それは '6/30/2016 12:00:00 AM'と同じです – user4912134

+0

あなたのフォーマットは' dd/MM/yyyy HH:mm:ss' – Nived

答えて

0

、あなた:私はのBizTalkを使用しておりますので、すべてのデータは、私が

public string ConvertDateCreated(string dateCreated) 
{ 
    System.Globalization.CultureInfo provider = System.Globalization.CultureInfo.InvariantCulture; 
    return DateTime.ParseExact(dateCreated, "MMddyyyy", provider).ToString("yyyyMMdd"); 
} 

enter image description here

のように次のスクリプトを使用しています。しかし、それはエラーを投げているように刺すように処理されますソース日付形式は"M/dd/yyyy hh:mm:ss tt"のようにする必要があります。

public static string ConvertDateCreated(string dateCreated) 
{ 
    System.Globalization.CultureInfo provider = 
     System.Globalization.CultureInfo.InvariantCulture; 
    return DateTime.ParseExact(dateCreated, "M/dd/yyyy hh:mm:ss tt", provider) 
      .ToString("yyyyMMdd"); 
} 
関連する問題