Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help! Inserting Date Data Types

Status
Not open for further replies.

Jonid

Programmer
May 4, 2001
24
AE
How Do i insert Date Data into Sql Server DB Using ADO objects???
i tried this but it didnt work

sql = "insert into table(datetimefield) values("
sql = sql & "'" & datevariable & "')"

cnn.execute sql
-----------------------------------------

error message i get is :
error converting datetime from char string

i tired useing now() function instead of datavariable for testing but i get the same message

any ideas???
 
Try putting the variable in #'s, instead of an apostrophe.
sql = sql & "#" & datevariable & "#)"

This should work... Good luck.

Doug
 
i get an error when i use #datevar#

im using this code in a VB Component not asp. there might be some diffs.
 
Sounds like your datetime variable isn't really one.

Try this:

sql = "insert into table(datetimefield) values("
sql = sql & "'" & CDate(datevariable) & "')"

Note also that "#" delimeters are for Access databases whereas "'" (single quotes, like you have it) are used for SQL Server

 
It Doesnt Seem To Work
any ways it works if i use command object and then assign date.

here is a sample


dim cm as new adodb.command
cm.commandtext = "insert into table values(?)"
cm.refresh
cm(0) = datevariable
cm.execute

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top