# TimeDate data type on MS SQL



## matikin9 (Jun 29, 2004)

I have a VB form that has a DateTime Picker for the user to set a date that will be put in a DateTime field of a table in a MS SQL database. But, I have no clue how to put the value of the dtp in the sql INSERT string properly. 

This is my [non-working] string:


```
strSQL = "Insert into tblARAT (strEmpNum,strAccessID,dttAssignedDate," + _
        "strAssignedBy) values ('" + txtEmpNum + "','" + txtAccessID + "','" + _
        dtpAssignedDate.Value + "','" + txtAssignedBy + "');"
```


----------



## Mithrilhall (Mar 28, 2001)

What are you getting back as an error?

Dump your strSQL to a label and post what that looks like.


----------



## GCDude (Apr 1, 2005)

sql datetime format can be many different forms, i use:-

yyyy/mm/dd hh:mm:ss

as there can be problems with localisation if use dd or mm first, likewise if u use characters as month 'JAN'.

Also noted you are trying to insert values into strEmpNum and strAccessID, are these strings? As they look like they maybe numbers and in your sql you have single quotes around these. singles quotes dont go around numbers in sql, only strings and dates.


----------



## matikin9 (Jun 29, 2004)

Thanks to the both of you, I figured out the problem. ^_^ It was actually really stupid, and I should have realized it when the debugger said my error was on the line with the string, not the line where I execute the string.  I threw up a CStr() around the "dtpAssignedDate.Value", and now it works. yay! ^_^


----------

