我取字符串變量列表日期項,然後我想將它插入SQL表中,但在SQL列類型是日期時間。所以我需要將字符串轉換爲DateTime。日期時間在SharePoint 2007
我使用下面的代碼:
DateTime strAllocatedOn;
string[] format = { "dd/MM/yyyy HH:mm:ss tt", "dd-MM-yyyy HH:mm:ss tt" };
DateTime.TryParseExact(dt.Rows[j]["Created"].ToString(), format, null, DateTimeStyles.None, out strAllocatedOn);
但是,得到如下錯誤:
這我recevingAn error occurred during the compilation of the requested file, or one of its dependencies. Invalid expression term 'out'
日期格式爲 「10/3/2011下午4時38分27秒」。
當心,因爲DateTime格式可以根據用戶的區域設置改變。但看着代碼,我覺得你做的事情不正確。 'dt.Rows [j]'是否真的返回一個字符串或DateTime? dt.Rows [j] .GetType()返回什麼? – 2012-01-05 10:38:13
嗨感謝您的答覆.. 是的,它是retunring我檢查它的日期。 – AndroidGuy 2012-01-05 11:31:24
這是一個編譯錯誤說,它得到了一個「出」的表達,當它沒有意義。你上面粘貼的代碼看起來很好。你確定它不是導致錯誤的代碼的另一部分嗎? – 2012-01-05 12:32:11