SQL Syntax error

Results 1 to 4 of 4

Thread: SQL Syntax error

  1. #1
    Join Date
    Dec 1969
    Posts
    716

    Default SQL Syntax error

    I am currently having problems passing a date variable named "thedate" through to an ASP which then matches that date to those existing in a database and shows the relevant records (ie the ones that match the date). When it finds a match it would show more information eg: Name, Age, Department etc<BR><BR>This is the actual code i&#039m using on the HTML page to pass through "thedate" (looks fine to me):<BR><BR>&#060;form action="showbydate.asp" method="post"&#062;<BR>&#060;input type="text" name="thedate"&#062;<BR>&#060;input type="submit" value="Submit"&#062;<BR>&#060;/form&#062;<BR><BR>This is the SQL Statement in the ASP:<BR><BR>SQLString = "SELECT * FROM Staff WHERE thedate = #" & thedate & "#"<BR><BR>The error message i&#039m getting when the ASP loads (or tries to) is as follows:<BR><BR>Syntax error in date query expression &#039thedate = ##&#039<BR><BR>This, to me - an ASP-newbie =) looks as though "thedate" variable is not being passed through properly - surely between the ##&#039s the contents of the variable should be? ie 11/08/99 ..<BR><BR>Hope you can help,<BR><BR>Thanks in advance,<BR><BR>Justin<BR><BR>

  2. #2
    Nathen Grass Guest

    Default RE: SQL Syntax error

    You&#039re right about the variable not being passed through properly. One thing I didn&#039t see in your code was the extraction of the variable from the Forms collection. If it isn&#039t in your code it needs to be there so the ASP page can get it.<BR><BR>theDate = Request.Form("thedate")

  3. #3
    Join Date
    Dec 1969
    Posts
    716

    Default RE: SQL Syntax error

    Ahhh ha - thanks Nathen - I was using the following:<BR><BR>thedate = Request.QueryString("thedate")<BR><BR>I&#039ll go amend it to Request.Form now - out of interest, whats the difference?<BR><BR>Cheers,<BR><BR>Justin<BR><BR><B R>

  4. #4
    Nathen Grass Guest

    Default RE: SQL Syntax error

    Which collection you use depends on the Method property of the Form that&#039s calling the ASP page. If you use POST (i.e &#060;form method=POST&#062;) then you use Request.Form to get the values. If you use GET (i.e. &#060;form method=GET&#062;) then you use Request.Querystring to get the values. <BR><BR>If you see an URL similiar to &#039page.asp?this=that&#039 everything after the ? is the querystring, so the values are passed in the URL. With the POST method all the values are passed in the body of the message that is sent to the server. If you have a lot of values in your form it&#039s probably better to use the POST method because you&#039re not limited on how much is passed, but you are with GET. The limit is different for each browser and I can&#039t remember them off the top of my head.


Posting Permissions

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