update smalldatetime in database

I need to update a sql database where the field is a smalldate and time.  I have converted the values from the text boxes to date and txttimeout to cdate but I keep getting the error Incorrect syntax near '4'.   The string is 3/27/2006 4:15:00 PM.   I am guessing it does not like the space.  How can I change the sql query to work with this.  Thanks

Dim strtimeout As string
      Dim strtimein As string
      Dim strdatein As string
      strdatein = txtdatein.text
      strtimein=cdate(strdatein & " " & txttimein.text)
      strtimeout= cdate(strdatein & " " & txttimeout.text)
      objCmd.Connection = objConn
                objCmd.CommandText = "UPDATE Employeehours SET timeout = " & strtimeout  & " where recordid = " & id      
                objRdr = objCmd.ExecuteReader()
      objConn.Close()
running32Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

cubixSoftwareCommented:
Hi

Try

objCmd.CommandText = "UPDATE Employeehours SET timeout = '" & strtimeout  & "' where recordid = " & id  

I think you need to enclose the date in single quotes like a character value

 
running32Author Commented:
I get the error Incorrect syntax near '='.
cubixSoftwareCommented:
mmmm.. it works for me so....

You definetly need the single quotes so keep them.

Can you go into SQL Query Analyzer and type your SQL statement and this should generate the same error.

Is the date and time settings on your client the same as the server ? Mine are set as UK (so DMY) but if I enter a date as MDY then I get your syntax error. If I enter your testdata as '27/3/2006 4:15:00 PM' then it works.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
OWASP: Threats Fundamentals

Learn the top ten threats that are present in modern web-application development and how to protect your business from them.

wtconwayCommented:
If your regional settings are YMD then try this:

Dim timeout as DateTime = CType(strtimeout,DateTime)

"UPDATE Employeehours SET timeout='" & timeout.ToString("yyyy/MM/dd hh:mm:ss") & "' where recordid=" & id

That way you can force the output of the date/time value.
running32Author Commented:
my regional setting are MDY
cubixSoftwareCommented:
Is that also true of the server where the SQL Server database resides  ?
running32Author Commented:
I tried something different and it worked.  Thanks for our help

Dim strtimeout As String
      Dim strtimein As String      
      intrecordid = txtid.text
      response.write (intrecordid)
      strtimeout = txtdatein.text & " " &  txttimeout.text
      strtimein = txtdatein.text & " " &  txttimein.text
      'strtimein = ctype(strtimein)
      response.write (strtimeout)
      
      strCmd = "UPDATE Employeehours SET timeout=@timeout, timein=@timein WHERE recordID=@recordID"
      objCmd = New SqlCommand(strCmd, objConn)
      objCmd.Parameters.Add("@timeout", strtimeout)
      objCmd.Parameters.Add("@timein", strtimein)
      objCmd.Parameters.Add("@recordid", intrecordid)
      objConn.Open()
      objCmd.ExecuteNonQuery()
      objConn.Close()
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.