Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with Displaying Full Text of Article Using Access/ASP

Status
Not open for further replies.

ChesterTheCat

IS-IT--Management
Sep 18, 2006
2
US
This should be simple enough. However, I'm missing something.

I have a MS Access database called Articles where I'm storing articles on the following 3 subjects: Employment, Bankruptcy and General legal issues.

Accordingly, I have three tables in the Articles database called:

Employment
Bankruptcy
General

I have an ASP page called articles.asp where I display a list of the articles by subject matter (i.e., Employment, Bankruptcy, General). Do do this, I created multiple recordsets. In each recordset, I display the article title, author and date of the article. So far, so good. I run into trouble, however, when I try to link the article title to the full-text of the article. The link is displayed on the articles.asp page, but when my display-employment-article.asp page is called, I get the following error message:

Microsoft JET Database Engine error '80040e07'
Data type mismatch in criteria expression.
display-employment-article.asp, line 17


Here's my code for articles.asp:

<%@ LANGUAGE=VBSCRIPT %>
<%Option Explicit%>
<%
Dim dbNCHC, strDBPath, connString, rsNCHC, Sql

Set dbNCHC = Server.CreateObject("ADODB.Connection")
strDBPath = "Articles.mdb"
connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(strDBPath) & ";"
dbNCHC.Open connString
Set rsNCHC = Server.CreateObject("ADODB.Recordset")

Sql = "SELECT * FROM Employment"_
& " ORDER BY Employment.EmpDate DESC"
rsNCHC.Open Sql, dbNCHC
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"<head>
<title>Articles Database</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
</head>
<body>
<h1><%=rsNCHC("EmpPracticeGrp")%></h1>
<br>
<%If rsNCHC.BOF and rsNCHC.EOF Then%>
<h2 align="center" style="text-align: left">No results found.</h2>
<%else%>
<hr style="margin-top: 5px" color="#49496E" size="1"></p>
<%Do While Not rsNCHC.EOF%>
<div align="left">
<table BORDER="0" width="94%" cellpadding="3" style="text-align: left; border-collapse:collapse" cellspacing="1" height="21">
<tr>
<td width="500">
<a class="style1" href="display-employment-article.asp?ID=<%=rsNCHC("EmpID")%>"><%=rsNCHC("EmpTitle")%></a><br>
<%=rsNCHC("EmpAuthor")%><br>
<%=rsNCHC("EmpDate")%>
</td>
</tr>
</table>
</div>
<%rsNCHC.MoveNext
loop
end if
rsNCHC.Close%>


<% Sql = "SELECT * FROM Bankruptcy" _
& " ORDER BY Bankruptcy.BkDate DESC"
rsNCHC.Open Sql, dbNCHC%>
<h1><%=rsNCHC("BkPracticeGrp")%></h1>
<br>
<%If rsNCHC.BOF and rsNCHC.EOF Then%>
<h2 align="center" style="text-align: left">No results found.</h2>
<%else%>
<hr style="margin-top: 5px" color="#49496E" size="1"></p>
<%Do While Not rsNCHC.EOF%>
<div align="left">
<table BORDER="0" width="94%" cellpadding="3" style="text-align: left; border-collapse:collapse" cellspacing="1" height="21">
<tr>
<td width="500">
<a class="style1" href="display-bankruptcy-article.asp?ID=<%=rsNCHC("BkID")%>"><%=rsNCHC("BkTitle")%></a><br>
<%=rsNCHC("BkAuthor")%><br>
<%=rsNCHC("BkDate")%>
</td>
</tr>
</table>
</div>
<%rsNCHC.MoveNext
loop
end if
rsNCHC.Close%>

<% Sql = "SELECT * FROM [General]" _
& " ORDER BY [General].GenDate DESC"
rsNCHC.Open Sql, dbNCHC%>
<h1><%=rsNCHC("GenPracticeGrp")%></h1>
<br>
<%If rsNCHC.BOF and rsNCHC.EOF Then%>
<h2 align="center" style="text-align: left">No results found.</h2>
<%else%>
<hr style="margin-top: 5px" color="#49496E" size="1"></p>
<%Do While Not rsNCHC.EOF%>
<div align="left">
<table BORDER="0" width="94%" cellpadding="3" style="text-align: left; border-collapse:collapse" cellspacing="1" height="21">
<tr>
<td width="500">
<a class="style1" href="display-general-article.asp?ID=<%=rsNCHC("GenID")%>"><%=rsNCHC("GenTitle")%></a><br>
<%=rsNCHC("GenAuthor")%><br>
<%=rsNCHC("GenDate")%>
</td>
</tr>
</table>
</div>
<%rsNCHC.MoveNext
loop
end if
rsNCHC.Close
dbNCHC.Close
set rsNCHC = nothing
set dbNCHC = nothing
%>
</body>
</html>

[/color red]

Here's my code for display-employment-article.asp:



<%@ LANGUAGE=VBSCRIPT %>
<%
Dim dbNCHC, strDBPath, connString, rsNCHC, Sql

Set dbNCHC = Server.CreateObject("ADODB.Connection")
strDBPath = "Articles.mdb"
connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(strDBPath) & ";"
dbNCHC.Open connString

'First get the passed parameters and handle embedded single quotes to stop SQL injection hacking
strEmpID = Replace(Request("EmpID"),"'","''")

' Now build the SQL query to find records matching the ID number
Sql = "SELECT * FROM Employment WHERE ((Employment.EmpID) = '" & strEmpID & "')"

'Open the recordset
set rsNCHC = dbNCHC.Execute(Sql)
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"<head>
<title>Display Full Text of Employment Article</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
</head>
<body>
<%If rsNCHC.BOF and rsNCHC.EOF Then%>
<h2 align="center" style="text-align: left">No results found.</h2>
<%else%>
<hr style="margin-top: 5px" color="#49496E" size="1"></p>
<%Do While Not rsNCHC.EOF%>
<div align="left">
<table BORDER="0" width="94%" cellpadding="3" style="text-align: left; border-collapse:collapse" cellspacing="1" height="21">
<tr>
<td width="500">
<%=rsNCHC("EmpAuthor")%><br>
<%=rsNCHC("EmpDate")%><br>
<%=rsNCHC("EmpTitle")%><br>
<%=rsNCHC("EmpBody")%>
</td>
</tr>
</table>
</div>
<%rsNCHC.MoveNext
loop
end if
rsNCHC.Close
dbNCHC.Close
set rsNCHC = nothing
set dbNCHC = nothing
%>
</body>
</html>
[/color red]
 
Not 100% sure but you might have a problem with the line: Sql = "SELECT * FROM Employment WHERE ((Employment.EmpID) = '" & strEmpID & "')"

How about trying: Sql = "SELECT * FROM Employment WHERE Employment.EmpID = '" & strEmpID & "' "

Hope this helps.
 
You have single quotes around a number. You have:

Sql = "SELECT * FROM Employment WHERE ((Employment.EmpID) = '" & strEmpID & "')"

Try:

Sql = "SELECT * FROM Employment WHERE ((Employment.EmpID) = " & strEmpID & ")"

That should fix you up...
 
Thansk buninghake,

It turns out the problem was with the ID link on the articles.asp page. Originally I wrote the link as so:

<a class="style1" href="display-employment-article.asp?ID=[/color red]

Instead I should have had this:

<a class="style1" href="display-employment-article.asp?EmpID=[/color red]

Thanks for your reply.

Chester

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top