Ask a Question related to ASP Database, Design and Development.

  1. #1

    Default Date query in ASP



    ASP/Scripting newbie question here. I have an access database that I am
    writing ASP pages to query and return the results. The end user can put
    in text, a beginning date, and an ending date. The script goes and
    returns the results based upon the information. I have the text portion
    OK, just trying to get the date thing going. Here is what I have so far
    (cosmetically it isn't much)

    *form method="post" action="time.asp"*
    Enter the beginning date for the query in the form mm/dd/yyyy:*br*
    *input type="text" name="begdate" size="10"**br**br*
    Enter the ending date for the query in the form mm/dd/yyyy:*br*
    *input type="text" name="enddate" size="10"*
    *input type=submit value="Submit Request"*

    time.asp file
    <%
    Dim objConn
    Set objConn=Server.CreateObject("ADODB.Connection")
    objConn.ConnectionString="DRIVER={Microsoft Access Driver (*.mdb)};" &
    "DBQ=\\fileserver\network\timeclock.mdb"

    objConn.Open
    Dim strSQL

    Dim rEmployee, rBegDate, rEndDate
    Set rEmployee = Request("Employee")
    Set rBegDate = Date Value(Request("begdate"))
    Set rEndDate = Date Value(Request("enddate"))

    strSQL="SELECT * FROM Timeclock WHERE UserName = '" & rEmployee & "'
    AND Date BETWEEN '" & rBegDate & "' AND '" & rEndDate & "'"

    Dim objRS
    Set objRS=Server.CreateObject("ADODB.Recordset")
    objRS.Open strSQL, objConn

    Do While Not objRS.EOF

    Response.Write "<b>" & objRS("UserName") & "</b> &nbsp &nbsp" &
    objRS("Event") & "&nbsp &nbsp" & objRS("Date") & "&nbsp &nbsp" &
    objRS("Time") & "<br>"

    objRS.MoveNext
    Loop
    objRS.Close
    Set objRS=Nothing
    objConn.Close
    Set objConn=Nothing
    %>

    I get the following:
    Microsoft VBScript compilation (0x800A0401)
    Expected end of statement

    on time.asp where I set rBegDate and rEndDate to the variables inputed
    from the form.

    Any help is appreciated.

    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    Horhayson Guest

  2. Similar Questions and Discussions

    1. date query problem, date in variable
      I am using the following query : $query_archief = "SELECT * FROM vacatures where dd_eind_plaatsing < $dd_eind_plaatsing_archief1" note:...
    2. More Date Query Problem
      Hi, I have written the code below to return only data that are recorded this month: <cfquery name="getInfo" datasource="main_acc" dbtype="odbc">...
    3. PHP Date Query
      I'm trying to create a recordset where I query a date field in my database. I can't figure the syntax. A little help here: WHERE Category =...
    4. Date Query
      I am attempting to pull information from a database and the main criteria of how I retrieve the information in a date format. The startdate and...
    5. a date query question
      I have this update query: UPDATE AccountsIpLogs SET LoggedIn = '0' I would like to add below WHERE statement but I don't know how to write it: ...
  3. #2

    Default Re: Date query in ASP

    VBScript function names don't contain spaces. Try using "DateValue" rather
    than "Date Value" (i.e.: no space between the "Date" and the "Value") for
    your date conversion.

    HTH,
    Nicole


    "Horhayson" <horhayson@nospamplease.net> wrote in message
    news:eAEOMJgqDHA.1680@TK2MSFTNGP10.phx.gbl...
    >
    >
    > ASP/Scripting newbie question here. I have an access database that I am
    > writing ASP pages to query and return the results. The end user can put
    > in text, a beginning date, and an ending date. The script goes and
    > returns the results based upon the information. I have the text portion
    > OK, just trying to get the date thing going. Here is what I have so far
    > (cosmetically it isn't much)
    >
    > *form method="post" action="time.asp"*
    > Enter the beginning date for the query in the form mm/dd/yyyy:*br*
    > *input type="text" name="begdate" size="10"**br**br*
    > Enter the ending date for the query in the form mm/dd/yyyy:*br*
    > *input type="text" name="enddate" size="10"*
    > *input type=submit value="Submit Request"*
    >
    > time.asp file
    > <%
    > Dim objConn
    > Set objConn=Server.CreateObject("ADODB.Connection")
    > objConn.ConnectionString="DRIVER={Microsoft Access Driver (*.mdb)};" &
    > "DBQ=\\fileserver\network\timeclock.mdb"
    >
    > objConn.Open
    > Dim strSQL
    >
    > Dim rEmployee, rBegDate, rEndDate
    > Set rEmployee = Request("Employee")
    > Set rBegDate = Date Value(Request("begdate"))
    > Set rEndDate = Date Value(Request("enddate"))
    >
    > strSQL="SELECT * FROM Timeclock WHERE UserName = '" & rEmployee & "'
    > AND Date BETWEEN '" & rBegDate & "' AND '" & rEndDate & "'"
    >
    > Dim objRS
    > Set objRS=Server.CreateObject("ADODB.Recordset")
    > objRS.Open strSQL, objConn
    >
    > Do While Not objRS.EOF
    >
    > Response.Write "<b>" & objRS("UserName") & "</b> &nbsp &nbsp" &
    > objRS("Event") & "&nbsp &nbsp" & objRS("Date") & "&nbsp &nbsp" &
    > objRS("Time") & "<br>"
    >
    > objRS.MoveNext
    > Loop
    > objRS.Close
    > Set objRS=Nothing
    > objConn.Close
    > Set objConn=Nothing
    > %>
    >
    > I get the following:
    > Microsoft VBScript compilation (0x800A0401)
    > Expected end of statement
    >
    > on time.asp where I set rBegDate and rEndDate to the variables inputed
    > from the form.
    >
    > Any help is appreciated.
    >
    > *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    > Don't just participate in USENET...get rewarded for it!

    Nicole Calinoiu Guest

  4. #3

    Default Re: Date query in ASP

    Change
    Date Value
    To
    DateValue


    Aside from that, let me suggest a few things so that as a newbie, maybe you
    can consider it now before you develop habits.

    1. Instead of using that connection string you're using, use an OLE DB
    equivalent connection string. [url]www.connectionstrings.com[/url]. See the OLEDB
    strings for Access.

    2. I'm going to assume that this page is running on a domain controller.
    If so, if at all possible, don't use IIS on a DC.

    3. When pulling values from the request, specify the collection you mean to
    pull from. Like, instead of Request("begdate"), use
    Request.Form("begdate"). If you don't specify, ASP will loop through the
    five different collections and pick the first match.
    [url]http://www.sloppycode.net/asp/?o=4[/url] If you have a querystring name with the
    same name as a form element, you'll get the querystring value.

    4. Don't pre-create an ADODB.Recordset object. See here.
    [url]http://www.aspfaq.com/2191[/url]

    5. Instead of using SELECT *, use SELECT
    [UserName],[Event],[Date],[Time]... [url]http://www.aspfaq.com/2096[/url]

    6. Beware of reserved SQL words. [url]http://www.aspfaq.com/2080[/url]

    7. Isn't it &nbsp;, not &nbsp? :]

    8. And for the perfectionist, instead of rs("name"), use
    rs.Fields.Item(0).Value (where 0 is the first column selected, 1 is the
    second, and so on).


    Ray at work




    "Horhayson" <horhayson@nospamplease.net> wrote in message
    news:eAEOMJgqDHA.1680@TK2MSFTNGP10.phx.gbl...
    >
    >
    > ASP/Scripting newbie question here. I have an access database that I am
    > writing ASP pages to query and return the results. The end user can put
    > in text, a beginning date, and an ending date. The script goes and
    > returns the results based upon the information. I have the text portion
    > OK, just trying to get the date thing going. Here is what I have so far
    > (cosmetically it isn't much)
    >
    > *form method="post" action="time.asp"*
    > Enter the beginning date for the query in the form mm/dd/yyyy:*br*
    > *input type="text" name="begdate" size="10"**br**br*
    > Enter the ending date for the query in the form mm/dd/yyyy:*br*
    > *input type="text" name="enddate" size="10"*
    > *input type=submit value="Submit Request"*
    >
    > time.asp file
    > <%
    > Dim objConn
    > Set objConn=Server.CreateObject("ADODB.Connection")
    > objConn.ConnectionString="DRIVER={Microsoft Access Driver (*.mdb)};" &
    > "DBQ=\\fileserver\network\timeclock.mdb"
    >
    > objConn.Open
    > Dim strSQL
    >
    > Dim rEmployee, rBegDate, rEndDate
    > Set rEmployee = Request("Employee")
    > Set rBegDate = Date Value(Request("begdate"))
    > Set rEndDate = Date Value(Request("enddate"))
    >
    > strSQL="SELECT * FROM Timeclock WHERE UserName = '" & rEmployee & "'
    > AND Date BETWEEN '" & rBegDate & "' AND '" & rEndDate & "'"
    >
    > Dim objRS
    > Set objRS=Server.CreateObject("ADODB.Recordset")
    > objRS.Open strSQL, objConn
    >
    > Do While Not objRS.EOF
    >
    > Response.Write "<b>" & objRS("UserName") & "</b> &nbsp &nbsp" &
    > objRS("Event") & "&nbsp &nbsp" & objRS("Date") & "&nbsp &nbsp" &
    > objRS("Time") & "<br>"
    >
    > objRS.MoveNext
    > Loop
    > objRS.Close
    > Set objRS=Nothing
    > objConn.Close
    > Set objConn=Nothing
    > %>
    >
    > I get the following:
    > Microsoft VBScript compilation (0x800A0401)
    > Expected end of statement
    >
    > on time.asp where I set rBegDate and rEndDate to the variables inputed
    > from the form.
    >
    > Any help is appreciated.
    >
    > *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    > Don't just participate in USENET...get rewarded for it!

    Ray at Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139