|
 |
access_asp thread: Date and Insert
Message #1 by kavitha_baskar@h... on Tue, 14 Aug 2001 03:39:47
|
|
Hi,
I am getting an Syntax Error in the following INSERT INTO statement:
sSQL = "INSERT into reservation(customer_id, room_num, reserve_date, time)
values('" & Request.form("customer_id") & "', '" & Request.Querystring
("n") & "', #" & date_s & "#, '" & Request.Querystring("t") & "')"
Set ns = oConn.Execute(sSQL)
I beleive something wrong with the date field,
i have defined date_s = Request.Querystring("d",) for example d=8/14/2001
can someone please help me?
Message #2 by "Padgett Rowell" <padgett@i...> on Tue, 14 Aug 2001 14:06:45 +0800
|
|
Try wrapping a cDate() around your Request line. I find explicitly
casting values prior to inserting them into a table cuts down on my
syntax errors.
Eg.
date_s = cDate(Request.Querystring("d"))
This might not be applicable in your scenario but I also tend to make
use of default values as much as possible. For example you could set
the default value of your date field in the database to equal Now() or
Date() (or GetDate() for SQL Server)
Another method you can use to isolate problems like this in asp is to
create a recordset object and assign each field individually. Something
like: ( I just typed this to give you an idea, it may contain syntax
errors, if you want a tested example, let me know)
Dim objConn
Dim objRs
Set objConn = Server.CreateObject("ADODB.Connection")
Set objRs = Server.CreateObject("ADODB.Recordset")
objConn.open DB_CONNECTIONSTRING
objRs.Open "Select * from my table where 1=2", objConn
objRs("mydate") = cDate(Request.Form("myDate"))
objRs("myField2") = Request.Form("myField2")
etc.
objRs.Update()
'cleanup
objRs.Close
Set objRs = Nothing
objCOnn.close
Set objConn = Nothing
This way if you get a type mismatch, it'll tell you what line (and what
field) the problem is with.
Cheers,
Padgett
-----Original Message-----
From: kavitha_baskar@h... [mailto:kavitha_baskar@h...]
Sent: Tuesday, 14 August 2001 3:40 AM
To: Access ASP
Subject: [access_asp] Date and Insert
Hi,
I am getting an Syntax Error in the following INSERT INTO statement:
sSQL = "INSERT into reservation(customer_id, room_num, reserve_date,
time)
values('" & Request.form("customer_id") & "', '" & Request.Querystring
("n") & "', #" & date_s & "#, '" & Request.Querystring("t") & "')"
Set ns = oConn.Execute(sSQL)
I beleive something wrong with the date field,
i have defined date_s = Request.Querystring("d",) for example
d=8/14/2001
can someone please help me?
|
|
 |