views:

18

answers:

1

Arithmetic overflow error converting expression to data type datetime. The statement has been terminated.

The culture of my site is en-gb (18/10/2010)

The culture of my db server is en-us (10/18/2010)

the date is stored in a param;

command.Parameters.AddWithValue("@bookingdate", inputBookingDate.Text)

Is there a way to convert this to US date format before entering into db?

I tried this code;

    Dim dbDate As String = command.Parameters("@bookingdate").Value.ToString
    dbdate = DateTime.Parse(dbdate, New CultureInfo("en-US"))
    command.Parameters("@bookingdate").Value = dbdate

But get the error 'String was not recognized as a valid DateTime.'

dbDate = "29/10/2010 00:00:00" 

How do I specify the current culture? identifying dbDate as a valid datetime in GB format.

Thanks.

A: 

Try DateTime.Parse. Read in the date in GB format, write it out in US format. Also a good time to check your UI code to make sure it is using GB formatting everywhere. Or change the format your DB expects.

If your DB supports it, you could write out the date as a timestamp to try and minimise the number of times you use the US date format.

Douglas