2013-05-03 40 views
0

我正在使用SSIS將數據從CSV文件上傳到我的數據庫中的表中。我試圖讓2串(一個是日期,另一個是時間)和CONCAT他們是這樣的:SSIS - 創建日期時間的腳本問題

string datsDateTime = String.Concat(Row.DATE, " ", Row.HEURE);  

然後,我嘗試分析它是這樣的:

Row.DateTime = DateTime.ParseExact(datsDateTime, "dd/MM/yyyy HH:mm", null); 

但它不起作用。當我嘗試測試這個腳本,我得到這個錯誤:

String was not recognized as a valid DateTime. 
    at System.DateTimeParse.ParseExact(String s, String format, DateTimeFormatInfo dtfi, DateTimeStyles style) 
    at ScriptMain.Input0_ProcessInputRow(Input0Buffer Row) 
    at UserComponent.Input0_ProcessInput(Input0Buffer Buffer) 
    at Microsoft.SqlServer.Dts.Pipeline.ScriptComponentHost.ProcessInput(Int32 inputID, PipelineBuffer buffer) 

我使用Visual Studio 2008的任何想法?

編輯:在我的專欄「日期」,這是我的csv文件,日期爲一個字符串,它是這樣的:(2012年01月和01天)。

UPDATE:好的,我通過考取任何事情之前做這個
string datsDateTime = Row.DATE.Insert(6,"/").Insert(4, "/") + " " + Row.HEURE; 找到了解決辦法。希望它會有所幫助。

回答

1

你或許應該改變格式

Row.FinalDate = DateTime.ParseExact(datsDateTime, "yyyyMMdd HH:mm", null); 

因爲你得到的日期在yyyymmdd格式 日期的存儲不是stringintegers。如果你想顯示DD/MM數據/ yyyy格式那麼你可以使用ToString()方法以特定的格式一樣

YourDate.ToString("dd/MM/yyyy") 

但因爲你在你的數據庫中存儲的話,它會被存儲爲整數 檢查您的sql服務器中的Dateformat

dbcc useroptions