Database problemer
Hey..Sidder og arbejder på en butik, og nu har jeg så været inde og rode rundt i noget, som jeg ikke har nogen anelse om hvordan jeg får løst.
Fejl meddelelsen:
Microsoft JET Database Engine error '80040e21'
You tried to execute a query that does not include the specified expression 'produktKategori' as part of an aggregate function.
/proff-hegn/productCatalog.asp, line 42
Her er koden til siden:
<% @ Language = VBScript %>
<%
Option Explicit
With Response
.Buffer = True
.Expires = 0
.Clear
End With
Dim viewCategory : viewCategory = request("cat")
Dim viewproduktUnderKategori : viewproduktUnderKategori = request("sCat")
Dim c, r, sql : sql = ""
Dim displayField, produktKatalogOptions, storeNavBar
if viewproduktUnderKategori = "" then
' there is no sub category query string
' so we are not displaying individual items
if viewCategory = "" then
' there is no category query string so
' let's display all the main categories
' displayField is the database field we
' will count and group below.
displayField = "produktKategori"
sql = "SELECT produktKategori, COUNT(produktKategori) AS majorCategories "
sql = sql & "FROM produktKatalog GROUP BY produktKategoril ORDER BY produktKategori;"
else
' we need to display the subCategories
' of the chosen category.
displayField = "produktUnderKategori"
sql = "SELECT produktUnderKategori, COUNT(produktUnderKategori) AS majorCategories "
sql = sql & "FROM produktKatalog WHERE produktKategori = '" & viewCategory & "' "
sql = sql & "GROUP BY produktUnderKategori ORDER BY produktUnderKategori;"
end if
set c = server.createobject("adodb.connection")
c.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.mappath("../dataentry/mydata.mdb")
set r = c.Execute(sql)
Do While NOT r.BOF AND NOT r.EOF
' display the categories or sub categories depending
' on the amount of query strings. The categories or sub categories
' displayed will be clickable links.
if viewCategory = "" then
produktKatalogOptions = produktKatalogOptions & _
"<a href=""./productCatalog.asp?cat=" & _
server.URLEncode(r(displayField)) & """><big>"
produktKatalogOptions = produktKatalogOptions & _
r(displayField) & "</big></a><br>" & vbCrLf
else
produktKatalogOptions = produktKatalogOptions & _
"<a href=""./productCatalog.asp?cat=" & _
server.URLEncode(viewCategory) & _
"&sCat=" & server.URLEncode(r(displayField)) & _
"""><big>"
produktKatalogOptions = produktKatalogOptions & _
r(displayField) & "</big></a><br>" & vbCrLf
end if
r.Movenext
LOOP
r.close : c.close : set r = nothing : set c = nothing
else
' displaying individual items based on the
' category and sub category chosen by the client when they
' click the catalog links.
sql = "SELECT produktNavn, produktBeskrivelse, produktPris, produktDiv, produktNummer FROM produktKatalog WHERE produktKategori = '" & viewCategory & "' "
sql = sql & "AND produktUnderKategori = '" & viewproduktUnderKategori & "' ORDER BY produktNavn;"
set c = server.createobject("adodb.connection")
c.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.mappath("../dataentry/mydata.mdb")
set r = server.createobject("adodb.recordset")
r.open sql, c
on error resume next
Do While NOT r.BOF AND NOT r.EOF
' display the items in that sub category.
produktKatalogOptions = produktKatalogOptions & _
"<strong>" & r(0) & "</strong><br>"
produktKatalogOptions = produktKatalogOptions & _
r(1) & "<br>" & "<i>" & _
formatcurrency(r(2), 2) & "</i><br>"
produktKatalogOptions = produktKatalogOptions & _
r(3) & "<br>"
' don't forget the add to cart button.
' What good is a product catalog
' if you can't select items to purchase?
produktKatalogOptions = produktKatalogOptions & _
"<a href=""./shoppingCart.asp?action=add&iNum=" & r(4) & """>"
produktKatalogOptions = produktKatalogOptions & _
"<font size=-1 face=arial>Tilføj til kurv</font></a><br><br>"
r.Movenext
LOOP
on error goto 0
r.close : c.close : set r = nothing : set c = nothing
end if
' now lets create a quick navigation bar for our catalog.
storeNavBar = ""
if viewCategory = "" AND viewproduktUnderKategori ="" then
' we are at home
storeNavBar = "home"
else
' we aren't at home so display the link to the main categories.
storeNavBar = "<a href=""./productCatalog.asp"">home</a> > "
if viewCategory <> "" then
' if there is a category to view then...
if viewproduktUnderKategori <> "" then
' display the sub category and a link to the category
storeNavBar = storeNavBar & "<a href=""./productCatalog.asp?cat=" & _
server.URLEncode(viewCategory) & """>"
storeNavBar = storeNavBar & viewCategory & _
"</a> > " & viewproduktUnderKategori
else
' display the category only
storeNavBar = storeNavBar & viewCategory
end if
end if
end if
%>
<html>
<head>
<title>Proff-hegn.dk</title>
<style type="text/css">
<!--
body {
background-color: #DED7A5;
}
-->
</style>
</head>
<body bgcolor="#EEEEEE">
<table width=100%>
<tr>
<td>
Navigation: <%=storeNavBar%>
</td>
<td valign=right>
<a href="./shoppingCart.asp">Indkøbskurv</a>
</td>
</tr>
</table>
<br><br>
<%=produktKatalogOptions%>
<br><br>
</body>
</html>