Re: SQL UPDATE for date data-type

Tech-Archive recommends: Fix windows errors by optimizing your registry



"glenn" <glenn@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:69AED76D-F11A-4E5D-9E8E-AE32AF7445C7@xxxxxxxxxxxxxxxx

Dim dtNow As DateTime = DateTime.Now
dRes = dtNow.ToShortDateString
Dim queryString As String = "UPDATE [rfi] SET [dateresolved] = dRes WHERE
([rfi].[id] = @id)"

dateresolved is a Date/Time data-type. The first snippet uses single
quotes
around the date but I would think the second snippet would be accepted as
a
string. If I debug the value of dRes, I receive the proper format of
"8/16/2006"

Yes, but SQL Server doesn't know that. If you're building up your SQL
dynamically, then you need to format it properly...

Dim queryString As String = "UPDATE [rfi] SET [dateresolved] = '" &
dRes.ToString("dd MMM yyyy") & "' WHERE ([rfi].[id] = @id)"

Any clues you can leave me with?

Use parameterised queries or, better still, stored procedures.


.