Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 16th, 2009, 05:16 PM
Authorized User
 
Join Date: Dec 2009
Posts: 16
Thanks: 1
Thanked 0 Times in 0 Posts
Default Problems with inserting Date() in Access using ASP

Dear all

Can anyone tell me why when I run the following script, which does work and does post data to the database, that it seems though to post the dates as times. So instead of posting the 'checkout_date' and 'duedate' as dates they get inserted into the database as time formats e.g. 00:00:57 and 00:10:45. Can anyone tell me whats going wrong?

Please see code below:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
If Request.Form("checkOut") then
customerID = Request.Form("customerID")
bookID = Request.Form("books")
checkedOutDate = Date()
dueDate = Date() + 30
Dim connString, sqlCheckOut, conn, sqlString
connString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("rltestingDB.mdb")
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open(connString)
sqlCheckOut = "INSERT INTO CUSTOMER_BOOKS (CUSTOMER_ID, BOOK_ID, CHECKED_OUT_DATE, DUE_DATE) VALUES (" & customerID & ", " & bookID & ", " & checkedOutDate & ", " & dueDate & ")"
conn.execute(sqlCheckOut)
'Response.Write(sqlCheckOut)
'Response.Write(Date())
conn.close
Set conn = Nothing
response.Redirect("checkOutDone.asp")
else
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Check book out</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="global.css" rel="stylesheet" type="text/css">
</head>
<body>

<%
Dim connString2, sqlBookList, conn2
connString2 = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("rltestingDB.mdb")
Set conn2 = Server.CreateObject("ADODB.Connection")
Set rsBookList = Server.CreateObject("ADODB.Recordset")
sqlBookList = "SELECT * FROM Books"
conn2.Open(connString2)
rsBookList.Open sqlBookList, conn2
%>
<fieldset>
<legend>Check Book Out</legend>
<div>
<form method="post" action="checkOut.asp">
<input type="hidden" name="checkOut" value="true">
<div><label for="Customer ID">Customer ID:</label><input type="text" name="customerID" /></div>
<div><label for="Book">Book:</label>
<select name="books">
<%while not rsBookList.eof%>
<option value="<%=rsBookList("BOOK_ID")%>"><%=rsBookList(" TITLE")%></option>
<%rsBookList.movenext
wend
%>
</select>
</div>
<div><input type="submit" value="Check out" /></div>
</form>
</div>
</fieldset>
<%
rsBookList.close
Set rsBookList = Nothing
conn2.close
Set conn2 = Nothing
%>
</body>
</html>
<%
End if
%>

Many thanks

Rob
 
Old December 16th, 2009, 05:45 PM
Authorized User
 
Join Date: Dec 2009
Posts: 16
Thanks: 1
Thanked 0 Times in 0 Posts
Default

I just worked it out, when I do it like the way below it inserts the dates correctly:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
If Request.Form("checkOut") then
customerID = Request.Form("customerID")
bookID = Request.Form("books")
Dim connString, sqlCheckOut, conn, sqlString
connString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("rltestingDB.mdb")
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open(connString)
sqlCheckOut = "INSERT INTO CUSTOMER_BOOKS (CUSTOMER_ID, BOOK_ID, CHECKED_OUT_DATE, DUE_DATE) VALUES (" & customerID & ", " & bookID & ", Date(), Date()+30)"
conn.execute(sqlCheckOut)
'Response.Write(sqlCheckOut)
'Response.Write(Date())
conn.close
Set conn = Nothing
response.Redirect("checkOutDone.asp")
else
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Check book out</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="global.css" rel="stylesheet" type="text/css">
</head>
<body>

<%
Dim connString2, sqlBookList, conn2
connString2 = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("rltestingDB.mdb")
Set conn2 = Server.CreateObject("ADODB.Connection")
Set rsBookList = Server.CreateObject("ADODB.Recordset")
sqlBookList = "SELECT * FROM Books"
conn2.Open(connString2)
rsBookList.Open sqlBookList, conn2
%>
<fieldset>
<legend>Check Book Out</legend>
<div>
<form method="post" action="checkOut.asp">
<input type="hidden" name="checkOut" value="true">
<div><label for="Customer ID">Customer ID:</label><input type="text" name="customerID" /></div>
<div><label for="Book">Book:</label>
<select name="books">
<%while not rsBookList.eof%>
<option value="<%=rsBookList("BOOK_ID")%>"><%=rsBookList(" TITLE")%></option>
<%rsBookList.movenext
wend
%>
</select>
</div>
<div><input type="submit" value="Check out" /></div>
</form>
</div>
</fieldset>
<%
rsBookList.close
Set rsBookList = Nothing
conn2.close
Set conn2 = Nothing
%>
</body>
</html>
<%
End if
%>

Thanks





Similar Threads
Thread Thread Starter Forum Replies Last Post
date field problem access asp varia_mahesh Access ASP 0 June 6th, 2007 08:33 AM
ASP/Access Date Format seananderson Classic ASP Databases 2 November 6th, 2006 02:15 PM
inserting yes/no value into Access DB using ASP pablohoney Classic ASP Basics 1 September 20th, 2005 12:00 AM
ASP 3.0 - Problems Inserting into Database w/ SQL Sunday Ironfoot ASP.NET 1.0 and 1.1 Basics 1 May 5th, 2004 02:41 PM
problems: asp files, from access to mysql karib MySQL 0 November 25th, 2003 04:07 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.