please help me for my code

R

riyaz

I am trying to display records depend on the current date & check with
database to display it in asp page.

for the below code i try to display records of "Announcement" field only by
checking the todays date
in the table by using the condition..by using this code it does not returns
any records from table

this is my MS-Acess database table:

fdate tdate Announcement Event Discussion
4/10/2006 4/30/2006 phrase1 phrase2 phrase3
1/5/2006 10/5/2006 text1 text2 text3

this is the code:

<%

Dim cn,rs
Dim sDate
Set cn = Server.CreateObject("ADODB.Connection")
Set rs = Server.CreateObject("ADODB.Recordset")

cn.Provider = "MicroSoft.jet.OLEDB.4.0"
cn = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Inetpub\wwwroot\webap\test.mdb"
rs.Open "display",cn,3,3

IF IsDate(Request.Form("Tcdate")) Then sDate=Cdate(Request.Form("Tcdate"))
%>

<%
Do While Not rs.EOF

If sDate>=rs("fdate") AND sDate<=rs("tdate") Then

Response.Write rs("Announcement")

end if

rs.MoveNext
loop
%>

<%
rs.close
set rs=nothing
%>


This is code by which i am getting the current date:

<input type="hidden" name="Tcdate" size="14" value="<%=Date()%>">

please help me to do this, any problem with database..

regards
Niyaz
 
R

Ronx

Try something like this: (not tested)

<%
dim mySQL
dim myConnString
dim myConnection
dim rsTemp
dim mydate
myConnString = Application("Database1_ConnectionString")
Set myConnection = Server.CreateObject("ADODB.Connection")
myConnection.Open myConnString
if isdate(request.form("mydate")) then
mydate=Cdate(request.form("mydate"))
else
mydate=Date()-36500
end if
mySql = "SELECT * From tablename WHERE ((mydate<=tdate) AND
(mydate>=fdate));"
set rsTemp = myConnection.execute(mySQL)

Do while not rsTemp.EOF
response.write rsTemp("Announcement")
rsTemp.movenext
loop
rsTemp.Close
set rsTemp = nothing
myConnection.Close
set myConnection = nothing
%>
 
R

Ronx

This is tested:

<%
dim mySQL
dim myConnString
dim myConnection
dim rsTemp
dim mydate
myConnString = Application("Database3_ConnectionString")
Set myConnection = Server.CreateObject("ADODB.Connection")
myConnection.Open myConnString
if isdate(request.form("EventDate")) then
mydate=Cdate(request.form("EventDate"))
else
mydate=Date()-36500
end if
mySql = "SELECT * FROM testDates WHERE (#" & mydate & "# BETWEEN Fdate
AND Ldate);"
set rsTemp = myConnection.execute(mySQL)

Do while not rsTemp.EOF
%>
<p><%=rsTemp("Event")%></p>
<%
rsTemp.movenext
loop
rsTemp.Close
set rsTemp = nothing
myConnection.Close
set myConnection = nothing
%>

See www.rxs-enterprises.org/fp/test/eventdate.asp
 
R

riyaz

i wrote the connection string in the code itself, is there any problem in
doing it,
i cannot get the records as eariler , please help me

my table( "display"):

fdate tdate Announcement Event Discussion
4/10/2006 4/30/2006 sample data1 sample data2 sample data3
5/1/2006 5/10/2006 sample phrase1 sample phrase2 sample phrase3

code:

<%
dim mySQL
dim myConnection
dim rsTemp
dim mydate

Set myConnection = Server.CreateObject("ADODB.Connection")
myConnection.Provider = "MicroSoft.jet.OLEDB.4.0"
myConnection.Open "C:\Inetpub\wwwroot\webap\test.mdb"

if isdate(request.form("Tcdate")) then
mydate=Cdate(request.form("Tcdate"))
else
mydate=Date()-36500
end if
mySql = "SELECT * FROM display WHERE (#" & mydate & "# BETWEEN fdate AND
tdate);"

set rsTemp = myConnection.execute(mySQL)

Do while not rsTemp.EOF
%>
<p><%=rsTemp("Event")%></p>
<%
rsTemp.movenext
loop
rsTemp.Close
set rsTemp = nothing
myConnection.Close
set myConnection = nothing
%>

i am getting the current date using this value <%=Date()%> as Tcdate

please help me , since there is no error message i am confused with this.

regards
Niyaz
 
R

riyaz

also i am not using a submit button. i am just checking the current date
from the page with data inside the table , automatically using this
<%=Date()%> from a textbox

please help me

niyaz
 
R

Ronx

If you are not submitting the form, then using a text-box will not be
of any use. The form must be submitted so that the data in the text
box can be read on the server.

Without submitting the form, all that will be shown are events based
on a hard coded date value or function; you can use (for current
events):

<%
dim mySQL
dim myConnection
dim rsTemp
dim mydate

Set myConnection = Server.CreateObject("ADODB.Connection")
myConnection.Provider = "MicroSoft.jet.OLEDB.4.0"
myConnection.Open "C:\Inetpub\wwwroot\webap\test.mdb"

mydate=Date()
mySql = "SELECT * FROM display WHERE (#" & mydate & "# BETWEEN fdate
AND tdate);"

set rsTemp = myConnection.execute(mySQL)

Do while not rsTemp.EOF
%>
<p><%=rsTemp("Event")%></p>
<%
rsTemp.movenext
loop
rsTemp.Close
set rsTemp = nothing
myConnection.Close
set myConnection = nothing
%>

The text box is not used and can be removed from the page. If you
want your users to be able to type in the date, then you need a submit
button, and the form action to be the same page, as per my example at
www.rxs-enterprises.org/fp/test/eventdate.asp
 
R

riyaz

thanks for your suggestions , code works.
so whenver we are not using form submission , we should get raw data without
creating any textboxes ..etc.

Thanks & regards
Niyaz
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top