2011-06-06 51 views
1

我一直試圖讓我的C#程序使用.NET業務連接器將記錄直接插入到2009年的數據庫中。通過業務連接器將dateTime字段插入到Dynamics AX數據庫中

到目前爲止,我可以伊斯利插入一個字符串,整數,Int64的,枚舉(諾伊斯),但它失敗每次我試圖和插入時間字段(AX中的字段定義爲UtcDateTime)出現錯誤:

The supplied method arguments are not valid.

我敢肯定,這是簡單的,我只是想念。

代碼片段:

using (axRecord = ax.CreateAxaptaRecord("TempTable")) 
     { 
      // Fails on this line with error: The supplied method arguments are not valid. 
      axRecord.set_Field("DateField", DateTime.Now); 

      axRecord.Insert(); 

     } 

我曾嘗試通過作爲一個字符串,並使用dateTime.parseExact等,但它似乎仍然沒有工作。

回答

1

它應該工作。

我做了一個靜態輔助類,並在我的項目包括它:

public static class MyHelperExtensions 
{  
     public static DateTime ParseDateAsString(this string value) 
     { 
      var culture = new CultureInfo("nb-NO"); 
      var formats = new[] {"ddMMyyyy", "dd.MM.yyyy"}; 
      DateTime date; 
      return DateTime.TryParseExact(value, formats, culture, DateTimeStyles.None, out date) ? date : DateTime.MinValue; 
     } 
} 

然後,我可以在值傳遞這樣的:

record.set_Field("StartDate", subscription.StartDate.ParseDateAsString()); 

現在,這個解決方案假定整個系統挪威文化。 值「記錄」是類型AxaptaRecord。

StartDate是一個擴展(最終)TransDate的字段。

我不明白爲什麼這不應該爲你工作。 這裏的一些其他提示:

  • 查找在事件查看器

  • 尋找在你的拼寫錯誤錯誤包含在字符串變量 (如 「開始日期」在我的例子)。

  • 開始在 Visual Studio和您的x ++代碼中添加斷點。 :)
+0

感謝您的支持,儘管它最初並沒有工作。我最終重新創建了桌子並獲得瞭解決方案。我假設我首先錯誤地創建了表格。雖然這兩個答案在這裏奏效,但我標記了這個答案,因爲它似乎解決了我面對多種日期時間格式的另一個問題。 – Zordey 2011-06-07 16:12:32

+0

很高興我能幫到你。 :) 它也可能是該表的以前版本中該列的數據類型的錯誤,但現在這是橋下的水。 – Skaue 2011-06-08 10:25:05

1

你可以試試這段代碼嗎?

using (axRecord = ax.CreateAxaptaRecord("TempTable")) 
{ 
    var xppDateTime = ax.CallStaticClassMethod("Global", "CLRSystemDateTime2UtcDateTime", DateTime.Now); 

    axRecord.set_Field("DateField", xppDateTime); 

    axRecord.Insert(); 

} 
+0

謝謝,upvoted,因爲這種解決方案的工作,但最終選擇使用其他的解決方案。 – Zordey 2011-06-07 16:16:19

相關問題