Problems converting a string to SQLDateTime

  • Thread starter Thread starter damon.f
  • Start date Start date
D

damon.f

I've got a classic ASP application that I'm migrating
to .NET. In the client script we used to use the
following code to help build up the sql string. It
converted a text date to the SQL Server Date format.

sSQL = sSQL + SQLServerDate(Request.Form
("PLANNEDEXITDATE")) + ","

I'm now trying to do this server side in VB.NET but I
can't seem to find a way to do it using convert or
CType. They all complain they cannot convert strings to
sqldatetime format. Also there seems to be no conversion
to a plain SQLServerDate.

mydate = CType(Convert.ToDateTime(PLANNEDEXITDATE),
SqlTypes.SqlDateTime)

I'm sure this is really simple but it's eluding me at
present. Does any one have an idea?

Thanks

Damon
 
You should just be able to do:

Dim myDate As SqlDateTime =
Convert.ToDateTime(Request.Form("PLANNEDEXITDATE"))

What's the error you get when using your original code?

Regards,

Mun
 
I've tried to use that converstion but it didn't work.

Interestingly I've just used DateTime.Parse() and that is
excepted!

My final line is:

sqlCmd.Parameters.Add(New SqlClient.SqlParameter
("@a_dtPlannedExitDate",
System.Data.SqlDbType.DateTime)).Value = DateTime.Parse
(PLANNEDEXITDATE)

Thanks for your effort

Damon
 
Back
Top