Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Other Forums
 Other Topics
 Date Issue!

Author  Topic 

acex10
Starting Member

13 Posts

Posted - 2005-01-04 : 00:18:34
Greeting. The following is my coding:

<%
Dim sqlstr, sqlstr1, sqlstr2
Dim rs, rs1, rs2

' Create a Connection
Dim DBConnection
Set DBConnection = Server.CreateObject("ADODB.Connection")
DBConnection.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("\Project\Campaign.mdb")

Dim DateNow
DateNow = Date

Set rs = Server.CreateObject("ADODB.RecordSet")
Set rs1 = Server.CreateObject("ADODB.RecordSet")
Set rs2 = Server.CreateObject("ADODB.RecordSet")

sqlstr = "Select * From LoadPage where DateInfo = " & DateNow

rs.Open sqlstr, DBConnection

If not rs.eof Then
sqlstr1 = "Update LoadPage Set Impressions = Impressions + 1 where DateInfo = " & DateNow
rs1.Open sqlstr1, DBConnection
Else
sqlstr2 = "Insert Into LoadPage(DateInfo, Impressions)Values(" & DateNow & ", 1)"
rs2.Open sqlstr2, DBConnection
End If

rs.Close
DBConnection.Close
%>

Why can't store the date into database? it does not give me the current date but 12/30/1988? What wrong with my code? Please help. Thanks in Advanced!

Stoad
Freaky Yak Linguist

1983 Posts

Posted - 2005-01-04 : 05:12:33
better

Else
sqlstr2 = "Insert Into LoadPage(DateInfo, Impressions)Values(Date, 1)"
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2005-01-04 : 07:12:30
1) Even in Access, you should always use parameters and not concatenate SQL strings

2) If you do create SQL on the fly, dates must be surrounded by # symbols:

sqlstr1 = "Update LoadPage Set Impressions = Impressions + 1 where DateInfo = #" & DateNow & "#"

- Jeff
Go to Top of Page
   

- Advertisement -