Pass HTML Form Date to VB Variable for SQL insertion -
alright, have simple asp page (summary.asp) - see code:
<html> <body> <form action = "summary.asp" method="post"> select day: <input type ="date" name = "selecteddate" /> <input type="submit" value = "submit"/> </form> <% dim selecteddate set selecteddate = date selecteddate=request.form("selecteddate")
after want use date selected part of sql query:
if selecteddate<>"" sql = "select location_name, [product code], sum(salesquantity) units [sales data] eventenddate = convert(date, getdate()) group [product code],location_name" ... end if %>
where intend replace "convert(date, getdate())" date selected in form.
i have not yet got part insert date form sql string. know date format html form in right format sql (yyyy-mm-dd), looks vb not format date? maybe i'm missing something, appreciated.
thanks... hope makes sense.
from can tell main problem trying explicitly declare selecteddate type. don't this. in vbscript variables of type variant
don't need declare type. can remove line:
set selecteddate = date
after should simple matter of casting string cdate
this
selecteddate = cdate(request.form("selecteddate"))
and sql line can add in this
sql = "select location_name, [product code], sum(salesquantity) units " &_ "from [sales data] eventenddate = " &_ selecteddate &_ " group [product code],location_name"
also note consider parameterized queries format ripe sql injection attack.
Comments
Post a Comment