输入字符串格式不正确 - foreach循环

时间:2015-04-16 19:06:16

标签: c# datetime ssis

Public Sub Main()

    Try
        ' Last load date
        dLastLoad = CType(Dts.Variables("User::PAR_LastLoadDate").Value, DateTime)

        ' Files to load
        dtFilesToLoad = CType(Dts.Variables("User::PAR_FilesToLoad").Value, DataTable)

        ' Parse file date out of file name
        strFileName = Dts.Variables("User::PAR_FileName").Value.ToString

        Dim temp As String
        temp = strFileName.Substring(strFileName.LastIndexOf("\") + 1, (strFileName.Length - (strFileName.LastIndexOf("\") + 1)))

        If temp.Length = Dts.Variables("$Package::PAR_SF_FileName").Value.ToString.Length Then

            strFileDate = strFileName.Substring(strFileName.Length - 12, 8)

            dFile = New DateTime( _
                Int32.Parse(strFileDate.Substring(0, 4)), _
                Int32.Parse(strFileDate.Substring(4, 2)), _
                Int32.Parse(strFileDate.Substring(6, 2)) _
            )

            dtMaxDate = DateTime.Parse(Dts.Variables("$Package::PAR_SF_MaxDate").Value.ToString, CultureInfo.InvariantCulture)

           ' Add row to data table when file date is more recent than last load date
            If dFile > dLastLoad And dFile <= dtMaxDate Then
                dtFilesToLoad.Rows.Add(New Object() {dFile, strFileName})
            End If

            Dts.Variables("User::PAR_FilesToLoad").Value = dtFilesToLoad

        End If

        Dts.TaskResult = ScriptResults.Success

    Catch ex As Exception

        Dts.Events.FireError(Nothing, String.Empty, ex.Message.ToString, String.Empty, Nothing)
        Dts.TaskResult = ScriptResults.Failure

    End Try
End Sub

我循环扩展文件扩展名为file_20140101_0100.fil(YYYYMMDD_hhmm)。 其他变量lastLoaddate也是日期时间类型。

我收到了错误

  

将字符串转换为datetime时,解析字符串以在将每个变量放入datetime对象之前获取日期。

0 个答案:

没有答案