Additional information: Invalid cast from Enum to DateTime.

0
August 18, 2011

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("@DateRepor

t").Value = Convert.ToDateTime(Trim(sp

(0))) 'Format(Convert.ToDateTime

(Trim(sp(0

))), "dd MMM yy")

                cmd.Parameters("@DateRepor

t").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").Va

lue = sp(4)

                cmd.Parameters("@IDOpe").V

alue = sp(6)

                cmd.Parameters("@Denominat

ion").Valu

e = 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(1

5))), "dd MMM yy")

                cmd.Parameters("@FromDate"

).Value = Format(Convert.ToDateTime(

Trim(sp(15

))), "dd MMM yy")

                cmd.Parameters("@CCY").Val

ue = sp(16)

                cmd.Parameters("@InterestA

ccrued").V

alue = Convert.ToDouble(sp(19))

                cmd.Parameters("@Valuation

").Value = Convert.ToDouble(sp(17))

                cmd.Parameters("@Percentag

eNav").Val

ue = Convert.ToDouble(sp(20))

                cmd.ExecuteNonQuery()

                nLineCount = nLineCount + 1

            Loop

            FileClose(1)

10

answers

Comments See all(0)

Add comment
0
August 18, 2011

then you can replace the Convert.ToDateTime calls with StringToDate in your code.

cmd.Parameters("@DateRepor

t").Value = Format(StringToDate(Trim(s

p(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").Va

lue = sp(4)

cmd.Parameters("@IDOpe").V

alue = sp(6)

cmd.Parameters("@Denominat

ion").Valu

e = 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 = Format(StringToDate(Trim(s

p(9))), "dd MMM yy")

End If

cmd.Parameters("@Nominal")

.Value = Convert.ToDouble(sp(12))

                '  cmd.Parameters("@FromDate"

).Value = StringToDate(Trim(sp(15)))

cmd.Parameters("@FromDate"

).Value = Format(StringToDate(Trim(s

p(15))), "dd MMM yy")

cmd.Parameters("@CCY").Val

ue = sp(16)

cmd.Parameters("@InterestA

ccrued").V

alue = Convert.ToDouble(sp(19))

cmd.Parameters("@Valuation

").Value = Convert.ToDouble(sp(17))cm

d.Paramete

rs("@Perce

ntageNav")

.Value = Convert.ToDouble(sp(20))

AW

0
August 18, 2011

what line is causing the error?

AW

0
August 18, 2011

The date line

0
August 18, 2011

which 'date line' there are several which utilize Convert.ToDateTime()

AW

0
August 18, 2011

the date that comes from the file is like this:

20060630;

How do I transfer it to 30 june 2006

0
August 18, 2011

you will need to parse the value:

        Dim field As String = "20060630"

        Dim testDate As Date = DateSerial(CInt(field.Subs

tring(0, 4)), CInt(field.Substring(4, 2)), CInt(field.Substring(6, 2)))

where Field is the name of the variable that holds the test "20060630"

you could do this in a Function:

Private Function ConvertStringtoDate(DateSt

ring as String) as Date

0
August 18, 2011

you will need to parse the value:

        Dim field As String = "20060630"

        Dim testDate As Date = DateSerial(CInt(field.Subs

tring(0, 4)), CInt(field.Substring(4, 2)), CInt(field.Substring(6, 2)))

where Field is the name of the variable that holds the test "20060630"

you could do this in a Function:

Private Function StringToDate(DateString as String) as Date

    If DateString.Length = 8 then

         Return DateSerial(CInt(DateString

.Substring

(0, 4)), CInt(DateString.Substring(

4, 2)), CInt(DateString.Substring(

6, 2)))

    End If

End Function

AW

0
August 18, 2011

How do I call this within my code

I create a new function as above but how do I pass in the values

Do Until EOF(1)

                sFileString = LineInput(1)

                sp = sFileString.Split(";")

                'cmd.Parameters("@DateRepo

rt").Value

= Convert.ToDateTime(sp(0)) 'Format(Convert.ToDateTime

(Trim(sp(0

))), "dd MMM yy")

                'cmd.Parameters("@DateRepo

rt").Value

= DateTime.Parse(sp(0))

                cmd.Parameters("@DateRepor

t").Value = Format(Convert.ToDateTime(

sp(0)), "M/dd/yyyy")

                'cmd.Parameters("@DateRepo

rt").Value

= Convert.ToDateTime(Trim(sp

(0))) 'Format(Convert.ToDateTime

(Trim(sp(0

))), "dd MMM yy")

                'cmd.Parameters("@DateRepo

rt").Value

= Format(Convert.ToDateTime(

Trim(sp(0)

)), "dd MMM yy")

                cmd.Parameters("@Quantity"

).Value = Convert.ToDouble(sp(12))

                If (Trim(sp(9))) = "" Then

                    cmd.Parameters("@ToDate").

Value = "01/01/1900"

                Else

                    cmd.Parameters("@ToDate").

Value = Convert.ToDateTime(Trim(sp

(11))) 'Format(Convert.ToDateTime

(Trim(sp(9

))), "dd MMM yy")

                    'cmd.Parameters("@ToDate")

.Value = Format(Convert.ToDateTime(

Trim(sp(9)

)), "dd MMM yy")

                End If

0
August 18, 2011

worked great thanks

0
August 18, 2011

glad to be of assistance.

AW

Related Questions

This is the very first question

Hello guys! This is the first post in this site Read More

Views

2k

Votes

4

Answers

2

January 08, 2016

report values not showing up.

I have a crystal report which I pass a DataSet to using VB.NET. The report was working fine, but then I make some changes to the import query and now nothing shows up in the crystal report. Crystal do Read More

Views

1k

Votes

0

Answers

12

September 06, 2005

Event log doesn't overwrite as needed in SP4

Hello All, After upgrading from SP3 to SP4 on several Windows 2000 PRO machines everything looked fine, but from time to time applications can't write to the event log. When I try to view the appl Read More

Views

1k

Votes

0

Answers

9

May 11, 2003

"Failed to self-register XYZ.dll"

Hi there, I wrote a OLE-automation-server DLL in VB4.0. I use Installshield Express to install it as part of my program on the target computers. Now on some computers I get the message "Failed to Read More

Views

8k

Votes

0

Answers

2

November 08, 1998

Please help understand these notes on image processing

Can someone please help me understand these lecture notes... On the right of the page; What does "normalised by one notion of the area of a pixel" mean? On the first formula for A, Is that a Read More

Views

1k

Votes

0

Answers

3

February 05, 2009

Can someone please explain this paragram on the chain rule in image processing

Please see the screenshot, How is 3133030 got from 10103322? Read More

Views

1k

Votes

0

Answers

1

January 05, 2009

AD on 2003

We have created an AD Domain on Windows 2000 Server with no problems. We just created an AD Domain on Windows 2003 and we're getting some weird problems. Both of these domains are behind firewalls Read More

Views

1k

Votes

0

Answers

15

May 11, 2003

ADDT ASP Upload Error " Type mismatch: 'tNG_isFileInsideBaseFolder' "

I am trying to create a simple insert record and upload image function on an ASP page built using Adobe Dreamweaver Developer Toolkit. I have done this many times before with no problem, however, i ha Read More

Views

1k

Votes

0

Answers

0

November 02, 2008

MYSQL Select query with custom ORDER BY

Hi, is it possible to customize the order of the returned rows in mysql? Example: I have a Table with a column "name", now I want to have all entries ordered by name, but I want the entries Read More

Views

1k

Votes

0

Answers

5

July 02, 2010

Folder Redirection in Server 2003

We have a Windows Server 2003 Standard Ed. Is there a way to redirect the users my documents to a folder that has already been created on the server? Read More

Views

1k

Votes

0

Answers

2

July 05, 2007

Partiton magic  version 8.0 having error 1523 while executing batch

I followed the partition magic 8.0 wizard to partition my hard disk while rebooting  I came across this problem  "error 1523 while executing batch" What can I do to solve this prob Read More

Views

1k

Votes

0

Answers

2

May 11, 2003

Please explain this paragraph in image processing (screenshot attached)

Two questions; How is the equation (10.1-15) formed? "are isotropic for rotation increments of 90 degrees and 45 degrees respectively" What does this mean Read More

Views

1k

Votes

0

Answers

7

January 05, 2009

xp_cmdshell with net use

Hi, when I use 'net use \192.168.0.1\c$ password /user:username' at the command prompt, it works fine.  But if i try to use it in sql with " exec master..xp_cmdshell 'net use \19 Read More

Views

983

Votes

0

Answers

5

April 11, 2003

hp ux11

i have a hp ux11 server. and i edited the /etc/resolv.conf to use my win2003 server dns server. That went fine, however, I would like to go the other way and add an entry on my win2003 dns to resolve Read More

Views

614

Votes

0

Answers

3

October 12, 2009

Using an application over a LAN

I have written an application that needs to be used on a LAN.  The application setup wizard takes care of registering everything on a single PC, but how do you go about writing a setup program th Read More

Views

538

Votes

0

Answers

9

August 07, 1998

Need subnet of 12 IPs.

Please, Can someone help me to create a subnet consisting of 12 IP's. Thanks.. Read More

Views

541

Votes

0

Answers

5

April 11, 2003

Drill down in a cross-tabl report

Hello, Would some experts to show me if it is possible to do drill-up or drill-down (or both) in a cross-tab report? I would also like to know if it is possible to control what fields to be displayed/ Read More

Views

439

Votes

0

Answers

0

September 06, 2005

Using RDO, Enterprise V Professional

We would like to use RDO on our project made up of 4 developers. Do we need to have a copy of Enterprise for each developer or is it possible to use Professional for those developers not writing the R Read More

Views

528

Votes

0

Answers

6

January 07, 1998

Can't Edit IIS Metabase.xml

We do this on every windows 2003 server and never had an issue. We cannot edit the IIS Metabase.xml We have stopped IIS and made change click save, no problem but it does not take the new information. Read More

Views

511

Votes

0

Answers

0

July 05, 2007

copy directorires - HP UNIX

Let's say my source file is /A/B/C/D/file1, and mytarget directory is /E/F/G, I want the result should look like this. /E/F/G/A/B/C/D/file1 I am using rsync to copy the files older than x no of da Read More

Views

547

Votes

0

Answers

14

September 12, 2009