troubleshooting Question

Additional information: Invalid cast from Enum to DateTime.

Avatar of BarepAssets
BarepAssetsFlag for Ireland asked on
Microsoft SQL Server.NET ProgrammingVisual Basic.NET
10 Comments1 Solution1051 ViewsLast Modified:
Error Converting to DateTime
Hi I have a sp and am trying to read a csv file which inputs the data into a table

but am getting the message, does anyone know why it is giving this error

When I test my sp with the values that it gives in the debugger all works fine

 FileOpen(1, stFile, OpenMode.Input)
            Do Until EOF(1)
                sFileString = LineInput(1)
                sp = sFileString.Split(";")
                '    With cmd

                '  cmd.Parameters("@DateReport").Value = Convert.ToDateTime(Trim(sp(0))) 'Format(Convert.ToDateTime(Trim(sp(0))), "dd MMM yy")
                cmd.Parameters("@DateReport").Value = Format(Convert.ToDateTime(Trim(sp(0))), "dd MMM yy")
                cmd.Parameters("@IDChorus").Value = Convert.ToInt32(sp(1))
                cmd.Parameters("@FundName").Value = sp(2)
                cmd.Parameters("@Country").Value = sp(3)
                cmd.Parameters("@Type").Value = sp(4)
                cmd.Parameters("@IDOpe").Value = sp(6)
                cmd.Parameters("@Denomination").Value = sp(7)
                cmd.Parameters("@Quantity").Value = Convert.ToDouble(sp(10))
                If (Trim(sp(9))) = "" Then
                    cmd.Parameters("@ToDate").Value = vbNull
                    '                    cmd.Parameters("@ToDate").Value = Convert.ToDateTime(Trim(sp(9))) 'Format(Convert.ToDateTime(Trim(sp(9))), "dd MMM yy")
                    cmd.Parameters("@ToDate").Value = Format(Convert.ToDateTime(Trim(sp(9))), "dd MMM yy")
                End If

                cmd.Parameters("@Nominal").Value = Convert.ToDouble(sp(12))
                '  cmd.Parameters("@FromDate").Value = Convert.ToDateTime(Trim(sp(15))) 'Format(Convert.ToDateTime(Trim(sp(15))), "dd MMM yy")
                cmd.Parameters("@FromDate").Value = Format(Convert.ToDateTime(Trim(sp(15))), "dd MMM yy")
                cmd.Parameters("@CCY").Value = sp(16)
                cmd.Parameters("@InterestAccrued").Value = Convert.ToDouble(sp(19))
                cmd.Parameters("@Valuation").Value = Convert.ToDouble(sp(17))
                cmd.Parameters("@PercentageNav").Value = Convert.ToDouble(sp(20))

                nLineCount = nLineCount + 1
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 10 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 10 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros