troubleshooting Question

Additional information: Invalid cast from Enum to DateTime.

Avatar of BarepAssets
BarepAssetsFlag for Ireland asked on
Visual Basic.NET.NET ProgrammingMicrosoft SQL Server
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
                Else
                    '                    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))

                cmd.ExecuteNonQuery()
                nLineCount = nLineCount + 1
            Loop
            FileClose(1)
ASKER CERTIFIED SOLUTION
Arthur_Wood

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Log in to continue reading
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform for $9.99/mo
View membership options
Unlock 1 Answer and 10 Comments.
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
The Value of Experts Exchange in My Daily IT Life

Experts Exchange (EE) has become my company's go-to resource to get answers. I've used EE to make decisions, solve problems and even save customers. OutagesIO has been a challenging project and... Keep reading >>

Mike

Owner of Outages.IO
Phoenix, Arizona, United States
Member Since 2016
Join a full scale community that combines the best parts of other tools into one platform.
Unlock 1 Answer and 10 Comments.
View membership options
“All of life is about relationships, and EE has made a virtual community a real community. It lifts everyone's boat.”
William Peck

Member since 2004