Problems converting a string to SQLDateTime

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
 
M

Munsifali Rashid

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
 
D

damon.f

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top