Hello,
I am new to VBscripting. I need to create ADOCommand sql string to select all records that are between user entered start date and end date and user entered county in a html form.
The main idea is to display a report based on the specified dates and counties in a form. I need to accept the values from the user and then pass those values to sql query string and process them.
I would like to know how do I pass these values to sql string without creating a Access procedure or query. Can we use ADOCommand parameters for this? If so, how do we do that. Please find the code below. Please help.
<%@Language=VBScript%>
<%Option Explicit%>
<!-- METADATA TYPE="typelib"
FILE="C:\Program Files\Common Files\System\ado\msado15.dll" -->
<HTML>
<HEAD>
<BODY>
<%
Dim objCommand, objRS
Dim strConnectionString
Dim DBPathName
Dim dtStartDt,dtEndDt,strCounty
Dim intNoofRecords
DBPathName = server.mappath("census.mdb")
strConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & DBPathName & ";"
Set objCommand = Server.CreateObject("ADODB.Command")
objCommand.ActiveConnection = strConnectionString
dtStartDt = Request.Form("eleStartDt")
dtEndDt = Request.Form("eleEndDt")
strCounty = Request.Form("elecounty")
objCommand.CommandText = "SELECT * FROM Participant WHERE Analysis_Date BETWEEN " & "Format(" & dtStartDt & "," & "'mm/dd/yy'" & ")" & " AND " & "Format(" & dtEndDt & "," & "'mm/dd/yy'" & ")" & _
" AND CountyID = " & "'" & strCounty & "'"
objCommand.CommandType = adCmdText
Set objRS = objCommand.Execute
intNoofRecords = objRS.recordcount
Set objCommand = Nothing
If intNoofRecords > 5 Then
' now loop through the records
While Not objRS.EOF
Response.Write objRS("Analysis_Date") & ": " & objRS("County") & "<BR>"
objRS.MoveNext
Wend
' now close and clean up
objRS.Close
Set objRS = Nothing
Else
msg = "There should be at least 5 participants to analyse the data"
Response.write ("<" & "script language=VBScript>")
Response.write ("Msgbox """ & msg & """<" & "/script>")
' now close and clean up
objRS.Close
Set objRS = Nothing
Response.Redirect "newApplication.asp"
End If
%>
</BODY>
</HTML>
I am new to VBscripting. I need to create ADOCommand sql string to select all records that are between user entered start date and end date and user entered county in a html form.
The main idea is to display a report based on the specified dates and counties in a form. I need to accept the values from the user and then pass those values to sql query string and process them.
I would like to know how do I pass these values to sql string without creating a Access procedure or query. Can we use ADOCommand parameters for this? If so, how do we do that. Please find the code below. Please help.
<%@Language=VBScript%>
<%Option Explicit%>
<!-- METADATA TYPE="typelib"
FILE="C:\Program Files\Common Files\System\ado\msado15.dll" -->
<HTML>
<HEAD>
<BODY>
<%
Dim objCommand, objRS
Dim strConnectionString
Dim DBPathName
Dim dtStartDt,dtEndDt,strCounty
Dim intNoofRecords
DBPathName = server.mappath("census.mdb")
strConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & DBPathName & ";"
Set objCommand = Server.CreateObject("ADODB.Command")
objCommand.ActiveConnection = strConnectionString
dtStartDt = Request.Form("eleStartDt")
dtEndDt = Request.Form("eleEndDt")
strCounty = Request.Form("elecounty")
objCommand.CommandText = "SELECT * FROM Participant WHERE Analysis_Date BETWEEN " & "Format(" & dtStartDt & "," & "'mm/dd/yy'" & ")" & " AND " & "Format(" & dtEndDt & "," & "'mm/dd/yy'" & ")" & _
" AND CountyID = " & "'" & strCounty & "'"
objCommand.CommandType = adCmdText
Set objRS = objCommand.Execute
intNoofRecords = objRS.recordcount
Set objCommand = Nothing
If intNoofRecords > 5 Then
' now loop through the records
While Not objRS.EOF
Response.Write objRS("Analysis_Date") & ": " & objRS("County") & "<BR>"
objRS.MoveNext
Wend
' now close and clean up
objRS.Close
Set objRS = Nothing
Else
msg = "There should be at least 5 participants to analyse the data"
Response.write ("<" & "script language=VBScript>")
Response.write ("Msgbox """ & msg & """<" & "/script>")
' now close and clean up
objRS.Close
Set objRS = Nothing
Response.Redirect "newApplication.asp"
End If
%>
</BODY>
</HTML>