Click to See Complete Forum and Search --> : Alert notice


bgrex1
02-25-2004, 11:25 PM
Is ther anyone that can help me with this, I want to have a small jpg file to show up beside a hyper link when a new post has been made in an asp page, eg a new report has been entered in the weekly report page and I want the new flashing logo to flash say there is a new entry for three days. Can this be done with java code.

buntine
02-26-2004, 12:54 AM
Yes, it can be done with java code.. But unless you've created your forum with Java, there is not point.

ASP can do it easily enough.. Why did you post aquestion about Java in the ASP forum?

TrustFly
02-26-2004, 03:04 AM
Sounds interesting.. How could this be done in ASP.NET?

bgrex1
02-26-2004, 03:22 AM
Buntine
I am a beginner wanting help did not realise that I asked in the wrong place, how can I now find out how to achieve what I asked using asp and msaccess data base.

buntine
02-26-2004, 05:43 AM
Its ok, you are in the correct place.

You will need to have a field in your MS Access database which stores the date at which each report has been stored. Each time the page is loaded, you could do a simple check to see whether the date in the currect database record is within three days of todays date.

Considering you are a beginner, you will probably need help with this as it is not a simple thing to achieve. Though, its definitely possible.

Just post if you would like me to help you further.

Regards,
Andrew Buntine.

buntine
02-26-2004, 05:44 AM
Sounds interesting.. How could this be done in ASP.NET?


Sure can, the same steps apply.

bgrex1
02-26-2004, 11:06 PM
Thank you for the offer, and yes I do need help how do you want to do it do you want my email if yes go to www.sdsfa.com this is the site that I have built you can contact me through Webmaster Email

PeOfEo
02-26-2004, 11:13 PM
Originally posted by TrustFly
Sounds interesting.. How could this be done in ASP.NET? of course. Oh wait someone answered this already.

buntine
03-13-2004, 11:39 PM
Concerning your email...

I will assume you have an access database on your server. We have to connect to the database and grab the newest record from it.
If you havent already done so, you will need to add a new field to a table in your database and name it id. Set it to 'autonumber' so it is automatically incremented each time a new record is entered into the table.

'|Dimension variables.
Dim conn, rs, sql, conn_string
Dim dteAdded, dteNow

'|Create ADO connection object and construct the connection string.
Set conn = server.createObject("ADODB.connection")
conn_string = "DBQ=" & server.mapPath("\subdir\yourDB.mdb") & ";"
conn_string = conn_string & "Driver={Microsoft Access Driver (*.mdb)}"
conn.open(conn_string) '|Open the database.

'|Create ADO recordSet object.
Set rs = server.createObject("ADODB.recordSet")
sql = "SELECT TOP 1 * FROM tableName ORDER BY id DESC;"
rs.open(sql), conn, 3 '|Execute SQL query.

'|Check for null return.
if rs.EOF and rs.BOF then
With Response
.write("Error: No records could be extracted...")
.flush
.end
End With
end if

rs.moveFirst '|Focus the first record.

'|Create the current date.
dteNow = CDate(Day(Now()) & "/" & Month(Now()) & "/" & Year(Now()))

'|Create the date the latest report was added.
if isDate(rs("dateEntered")) then
dteAdded = rs("dateEntered")
else
dteAdded = CDate(rs("dateEntered"))
end if

With Response
.write ("<a href=""showReports.asp"">")
.write ("Click here to see the weekly reports.")
.write ("</a>" & vbCrLf)

'|Determine whether the newest report has been there for 3 days or less.
if dateDiff("d", dteAdded, dteNow) <= 3 then
.write ("<img src=""newReport.gif"" alt=""a new report has been added"" border=""0"" />" & vbCrLf)
end if
End With

'|Close ADO objects to free up resources...
rs.close
set rs = nothing
conn.close
set conn = nothing


The preceding code has not been tested so it may not work first try.

Obviously, you will have to alter a number of things including:
- database name and path.
- connection string. (mayby)
- name of the table. Currently 'tableName'
- name of DB table field. currently set to 'dateEntered'
- filename of ASP script which displays reports. Currently 'showReports.asp'

The function which actually checks to see how old the newest record is, is VBScripts DateDiff() function. As the name implies, this function returns the difference between two dates. There are a number of different intervals which you can use.

This script should be placed on the page which contains the link to the script which displays the reports. Both pages must have a .asp file extenson.

Regards,
Andrew Buntine.

buntine
03-13-2004, 11:46 PM
lol. I hope i have understood you correctly.

bgrex1
03-15-2004, 05:26 PM
Thank you
Will give this a try and will let you know the outcome

bgrex1
03-18-2004, 01:12 AM
ADODB.Recordset error '800a0bb9'

Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.

/content21.asp, line 24

This is the error message that I get after I have placed your script on my sever.
I have been through it bit by bit and I'm not able to workout the problem.
I have got a field that is an autonumber id in the data base as you requested
the following is what I have placed on the net,
the conection string works on other asp pages so I dont think it is that.

any help please
<%
xDb_Conn_Str = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.mappath("/823reports/reportsdata.mdb") & ";User Id=admin;Password=;"
%>

<%
'|Dimension variables.
Dim conn, rs, sql, conn_string
Dim dteAdded, dteNow
%>

<%
'|Create ADO recordSet object.
Set rs = server.createObject("ADODB.RecordSet")
sql = "SELECT * FROM rep ORDER BY id DESC;"
rs.open(sql), conn, 3 '|Execute SQL query.


'|Check for null return.
if rs.EOF and rs.BOF then
With Response
.write("Error: No records could be extracted...")
.flush
.end
End With
end if

rs.moveFirst '|Focus the first record.

'|Create the current date.
dteNow = CDate(Day(Now()) & "/" & Month(Now()) & "/" & Year(Now()))

'|Create the date the latest report was added.
if isDate(rs("title")) then
dteAdded = rs("title")
else
dteAdded = CDate(rs("title"))
end if

With Response
.write ("<a href=""showReports.asp"">")
.write ("Click here to see the weekly reports.")
.write ("</a>" & vbCrLf)


'|Determine whether the newest report has been there for 3 days or less.
if dateDiff("d", dteAdded, dteNow) <= 3 then
.write ("<img src=""new.gif"" alt=""a new report has been added"" border=""0"" />" & vbCrLf)
end if

End With

'|Close ADO objects to free up resources...
rs.close
set rs = nothing
conn.close
set conn = nothing
%>

The preceding code has not been tested so it may not work first try.

Obviously, you will have to alter a number of things including:
- database name and path.
- connection string. (mayby)
- name of the table. Currently 'tableName'
- name of DB table field. currently set to 'dateEntered'
- filename of ASP script which displays reports. Currently 'showReports.asp'

The function which actually checks to see how old the newest record is, is VBScripts DateDiff()
function. As the name implies, this function returns the difference between two dates.
There are a number of different intervals which you can use.

This script should be placed on the page which contains the link to the script which
displays the reports. Both pages must have a .asp file extenson.

buntine
03-18-2004, 03:43 AM
EDIT: Disregard this post. Please refer to the post below for the solution to your problem.


rs.open(sql), conn, 3 '|Execute SQL query.


The problem lies in this line.. When you are opening a recordSet, you need to specify the name of the connection object you are using.
In my example, the name of the connection object was 'conn'. However, in your script, the object name is 'xDb_Conn_Str'.

Change the line to this:

rs.open(sql), xDb_Conn_Str, 3 '|Execute SQL query.


You will also need to edit the other lines which use the 'conn' variable.

conn.close
Set conn = nothing

Must be changed to

xDb_Conn_Str.close
Set xDb_Conn_Str = nothing


Regards,
Andrew Buntine.

buntine
03-18-2004, 03:47 AM
Actually, on second inspection, i have realised what you are trying to do..

You havent opened your connection object. You will need to add this snippet of code to you application.

Set conn = server.createObject("ADODB.connection")
xDb_Conn_Str = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.mappath("/823reports/reportsdata.mdb") & ";User Id=admin;Password=;"
(*.mdb)}"
conn.open(xDb_Conn_Str) '|Open the database.


Leave all the conn statements as they are.

Regards,
Andrew Buntine.