Esatto. Ti posto per completezza tutto il codice.
Grazie. Antonella
<%@ Language=VBScript %>
<!-- METADATA TYPE="typelib" UUID="00000200-0000-0010-8000-00AA006D2EA4" NAME="ADO Type Library"-->
<%
Option Explicit
Response.Buffer = True 'Turn buffering on
Response.Expires = -1 'Page expires immediately
'Constants
Const MIN_PAGESIZE = 5 'Minimum pagesize
Const MAX_PAGESIZE = 20 'Maximum pagesize
Const DEF_PAGESIZE = 10 'Default pagesize
'Variables
Dim objCn 'ADO DB connection object
Dim objRs 'ADO DB recordset object
Dim blnWhere 'True/False for have WHERE in sql already
Dim intRecord 'Current record for paging recordset
Dim intPage 'Requested page
Dim intPageSize 'Requested pagesize
Dim sql 'Dynamic sql query string
'Create objects
Set objCn = Server.CreateObject("ADODB.Connection")
Set objRs = Server.CreateObject("ADODB.Recordset")
'Set/initialize variables
intRecord = 1
blnWhere = False
'-Get/set requested page
intPage = MakeLong(Request("page"))
If intPage < 1 Then intPage = 1
'-Get/set requested pagesize
If IsEmpty(Request("pagesize")) Then'Set to default
intPageSize = DEF_PAGESIZE
Else
intPageSize = MakeLong(Request("pagesize"))
'Make sure it fits our min/max requirements
If intPageSize < MIN_PAGESIZE Then
intPageSize = MIN_PAGESIZE
ElseIf intPageSize > MAX_PAGESIZE Then
intPageSize = MAX_PAGESIZE
End If
End If
'-Build dynamic sql
sql = "SELECT ID, NOME, INDIRIZZO, TELEFONO, FAX, COMUNE, PROVINCIA, CATEGORIA, FIGURA FROM Tabella "
'--ID (exact search only)
If Not IsEmpty(Request("id")) Then
If IsNumeric(Request("id")) Then
'Add to query
'First item so we don't have to test for WHERE
blnWhere = True 'Set where to true
sql = sql & "WHERE "
sql = sql & "(ID = " & CStr(CLng(Request("id"))) & ") "
End If
End If
'--NOME (partial and exact search)
If Not IsEmpty(Request("NOME")) Then
Dim strNOME
strNOME = Trim(Request("NOME"))
If strNOME <> "" Then
'Test for WHERE
If blnWhere Then sql = sql & "AND " Else sql = sql & "WHERE " : blnWhere = True
If (Left(strNOME, 1) = "*" And Len(strNOME) > 1) Then'Partial search
sql = sql & "(NOME LIKE '%" & Replace(Mid(strNOME, 2), "'", "''") & "') "
ElseIf (Right(strNOME, 1) = "*" And Len(strNOME) > 1) Then'Partial search
sql = sql & "(NOME LIKE '" & Replace(Mid(strNOME, 1, Len(strNOME)-1), "'", "''") & "%') "
Else'Exact match
sql = sql & "(NOME = '" & Replace(strNOME, "'", "''") & "') "
End If
End If
End If
'--COMUNE (partial and exact search)
If Not IsEmpty(Request("COMUNE")) Then
Dim strCOMUNE
strCOMUNE = Trim(Request("COMUNE"))
If strCOMUNE <> "" Then
'Test for WHERE
If blnWhere Then sql = sql & "AND " Else sql = sql & "WHERE " : blnWhere = True
If (Left(strCOMUNE, 1) = "*" And Len(strCOMUNE) > 1) Then'Partial search
sql = sql & "(COMUNE LIKE '%" & Replace(Mid(strCOMUNE, 2), "'", "''") & "') "
ElseIf (Right(strCOMUNE, 1) = "*" And Len(strCOMUNE) > 1) Then'Partial search
sql = sql & "(COMUNE LIKE '" & Replace(Mid(strCOMUNE, 1, Len(strCOMUNE)-1), "'", "''") & "%') "
Else'Exact match
sql = sql & "(COMUNE = '" & Replace(strCOMUNE, "'", "''") & "') "
End If
End If
End If
'--PROVINCIA (partial and exact search)
If Not IsEmpty(Request("PROVINCIA")) Then
Dim strPROVINCIA
strPROVINCIA = Trim(Request("PROVINCIA"))
If strPROVINCIA <> "" Then
'Test for WHERE
If blnWhere Then sql = sql & "AND " Else sql = sql & "WHERE " : blnWhere = True
If (Left(strPROVINCIA, 1) = "*" And Len(strPROVINCIA) > 1) Then'Partial search
sql = sql & "(PROVINCIA LIKE '%" & Replace(Mid(strPROVINCIA, 2), "'", "''") & "') "
ElseIf (Right(strPROVINCIA, 1) = "*" And Len(strPROVINCIA) > 1) Then'Partial search
sql = sql & "(PROVINCIA LIKE '" & Replace(Mid(strPROVINCIA, 1, Len(strPROVINCIA)-1), "'", "''") & "%') "
Else'Exact match
sql = sql & "(PROVINCIA = '" & Replace(strPROVINCIA, "'", "''") & "') "
End If
End If
End If
'--CATEGORIA (exact search only)
If Not IsEmpty(Request("CATEGORIA")) Then
If IsNumeric(Request("CATEGORIA")) Then
'Add to query
'First item so we don't have to test for WHERE
blnWhere = True 'Set where to true
sql = sql & "WHERE "
sql = sql & "(CATEGORIA = " & CStr(CLng(Request("CATEGORIA"))) & ") "
End If
End If
'--Dynamic sql finished
'Create and open connection object
With objCn
.CursorLocation = adUseClient
.ConnectionTimeout = 15
.CommandTimeout = 30
.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Server.MapPath("DBASE/DATABASE.mdb") & ";"
.Open
End With
'Create and open recordset object
With objRs
.ActiveConnection = objCn
.CursorLocation = adUseClient
.CursorType = adOpenForwardOnly
.LockType = adLockReadOnly
.Source = sql
.PageSize = intPageSize
.Open
Set .ActiveConnection = Nothing'Disconnect the recordset
End With
'Creates a long value from a variant, invalid always set to zero
Function MakeLong(ByVal varValue)
If IsNumeric(varValue) Then
MakeLong = CLng(varValue)
Else
MakeLong = 0
End If
End Function
'Returns a neatly made paging string, automatically configuring for request
'variables, regardless of in querystring or from form, adjust output to your needs.
Function Paging(ByVal intPage, ByVal intPageCount, ByVal intRecordCount)
Dim strQueryString
Dim strScript
Dim intStart
Dim intEnd
Dim strRet
Dim i
If intPage > intPageCount Then
intPage = intPageCount
ElseIf intPage < 1 Then
intPage = 1
End If
If intRecordCount = 0 Then
strRet = "No Records Found"
ElseIf intPageCount = 1 Then
strRet = "End Of Hits"
Else
For i = 1 To Request.QueryString.Count
If LCase(Request.QueryString.Key(i)) <> "page" Then
strQueryString = strQueryString & "&"
strQueryString = strQueryString & Server.URLEncode(Request.QueryString.Key(i)) & "="
strQueryString = strQueryString & Server.URLEncode(Request.QueryString.Item(i))
End If
Next
For i = 1 To Request.Form.Count
If LCase(Request.Form.Key(i)) <> "page" Then
strQueryString = strQueryString & "&"
strQueryString = strQueryString & Server.URLEncode(Request.Form.Key(i)) & "="
strQueryString = strQueryString & Server.URLEncode(Request.Form.Item(i))
End If
Next
If Len(strQueryString) <> 0 Then
strQueryString = "?" & Mid(strQueryString, 2) & "&"
Else
strQueryString = "?"
End If
strScript = Request.ServerVariables("SCRIPT_NAME") & strQueryString
If intPage <= 10 Then
intStart = 1
Else
If (intPage Mod 10) = 0 Then
intStart = intPage - 9
Else
intStart = intPage - (intPage Mod 10) + 1
End If
End If
intEnd = intStart + 9
If intEnd > intPageCount Then intEnd = intPageCount
strRet = "Page " & intPage & " of " & intPageCount & ": "
If intPage <> 1 Then
strRet = strRet & "<a href=""" & strScript
strRet = strRet & "page=" & intPage - 1
strRet = strRet & """><<Prev</a> "
End If
For i = intStart To intEnd
If i = intPage Then
strRet = strRet & "<b>" & i & "</b> "
Else
strRet = strRet & "<a href=""" & strScript
strRet = strRet & "page=" & i
strRet = strRet & """>" & i & "</a>"
If i <> intEnd Then strRet = strRet & " "
End If
Next
If intPage <> intPageCount Then
strRet = strRet & " <a href=""" & strScript
strRet = strRet & "page=" & intPage + 1
strRet = strRet & """>Next>></a> "
End If
End If
Paging = strRet
End Function
%>
<html>
<head>
<title>Ricerca su Database CLIENTE</title>
<style>
BODY
{
FONT-WEIGHT: normal;
FONT-SIZE: 9pt;
COLOR: black;
FONT-FAMILY: Arial, Helvetica, sans-serif;
TEXT-DECORATION: none
}
TABLE
{
FONT-WEIGHT: normal;
FONT-SIZE: 9pt;
COLOR: black;
FONT-FAMILY: Arial, Helvetica, sans-serif;
TEXT-DECORATION: none
}
A
{
FONT-WEIGHT: normal;
FONT-SIZE: 9pt;
COLOR: blue;
FONT-FAMILY: Arial, Helvetica, sans-serif;
TEXT-DECORATION: underline
}
HR
{
COLOR: #0072bc
}
</style>
</head>
<body onload="javascript: document.frmSearch.id.select();">
<table border="0" width="100%" cellpadding="2" cellspacing="2">
<tr><td align=center><h3>Ricerca su Database CLIENTE</h3></td></tr>
<tr><td align=center><a href="mailto:info@PXCV.it">info@PXCV.it</a></td></tr>
<tr><td><hr></td></tr>
<!--Search Form-->
<form name="frmSearch" method="post" action="<%=Request.ServerVariables("SCRIPT_NAME")%>">
<input type="hidden" name="page" value="1">
<tr>
<td align=center>
<table border="0" width="100%" cellpadding="2" cellspacing="2">
<tr>
<td colspan="2"><b><font size="3"><font color="#336699">Opzioni di ricerca nominativo</font></b></td>
</tr>
<tr>
<td nowrap><b><u>I</u>D Nominativo:</b></td>
<td width="100%"><input accesskey="i" type="text" name="id" size="10" value="<%=Server.HTMLEncode(Request("id"))%>"> (Ricerca esatta)</td>
</tr>
<tr>
<td nowrap><b><u>N</u>ome:</b></td>
<td width="100%"><input accesskey="s" type="text" name="NOME" size="20" value="<%=Server.HTMLEncode(Request("NOME"))%>"> (Nome della macelleria o del ristorante)</td>
</tr>
<tr>
<td nowrap><b><u>C</u>omune:</b></td>
<td width="100%"><input accesskey="t" type="text" name="COMUNE" size="20" value="<%=Server.HTMLEncode(Request("COMUNE"))%>"> (Ricerca parziale o esatta)</td>
</tr>
<tr>
<td nowrap><b><u>P</u>rovincia:</b></td>
<td width="100%"><input accesskey="t" type="text" name="PROVINCIA" size="20" value="<%=Server.HTMLEncode(Request("PROVINCIA"))%>"> (Ricerca parziale o esatta)</td>
</tr>
<tr>
<td nowrap><b><u>C</u>ategoria:</b></td>
<td width="100%"><input accesskey="t" type="text" name="CATEGORIA" size="20" value="<%=Server.HTMLEncode(Request("CATEGORIA"))%>"> (Ricerca parziale o esatta)</td>
</tr>
<tr>
<td nowrap><b><u>L</u>inee Per Pagina:</b></td>
<td width="100%"><input accesskey="r" type="text" name="pagesize" size="10" value="<%=intPageSize%>"></td>
</tr>
<tr>
<td colspan="2">
<input type="button" name="btnRestart" value="Ricomincia" onclick="javascript: window.location='<%=Request.ServerVariables("SCRIPT_NAME")%>'">
<input type="submit" name="btnSubmit" value="Go!">
</td>
</tr>
</table>
</td>
</tr>
</form>
<tr><td><hr></td></tr>
<%If objRs.EOF Then%>
<!--No Records Found-->
<tr><td align="center"><b><font size="4">Nessun nominativo!</font></b></td></tr>
<%Else%>
<!--Records Found-->
<tr>
<td>
<table border="0" width="100%" cellpadding="3" cellspacing="3">
<tr><td colspan=4><b>Nominativi trovati: <%=objRs.RecordCount%></td></tr>
<tr><td align="center" colspan="4"><%=Paging(intPage, objRs.PageCount, objRs.RecordCount)%></td></tr>
<tr bgcolor="#efefef">
<td nowrap width="3%"><b>ID</b></td>
<td nowrap><b>Nome</b></td>
<td nowrap width="100%"><b>Indirizzo</b></td>
<td nowrap><b>Telefono</b></td>
<td nowrap><b>Fax</b></td>
<td nowrap><b>Comune</b></td>
<td nowrap><b>Provincia</b></td>
<td nowrap><b>Categoria</b></td>
<td nowrap><b>Figura</b></td>
</tr>
<%
If objRs.PageCount < intPage Then intPage = objRs.PageCount
objRs.AbsolutePage = intPage
Dim strRowColor
strRowColor = "#ffffff"
Do While Not objRs.EOF And intRecord <= intPageSize
%>
<tr bgcolor="<%=strRowColor%>">
<td nowrap><%=objRs("ID").Value%></td>
<td nowrap><%=objRs("NOME").Value%></td>
<td nowrap><%=objRs("INDIRIZZO").Value%></td>
<td nowrap><%=objRs("TELEFONO").Value%></td>
<td nowrap><%=objRs("FAX").Value%></td>
<td nowrap><%=objRs("COMUNE").Value%></td>
<td nowrap><%=objRs("PROVINCIA").Value%></td>
<td nowrap><%=objRs("CATEGORIA").Value%></td>
<td><img border=0 src="<%=objRs("FIGURA").Value%>" name="Image1">
</tr>
<%
If strRowColor = "#ffffff" Then strRowColor = "#90ee90" Else strRowColor = "#ffffff"
intRecord = intRecord + 1
objRs.MoveNext
Loop
%>
<tr><td colspan="4"><hr></td></tr>
<tr><td align="center" colspan="4"><%=Paging(intPage, objRs.PageCount, objRs.RecordCount)%></td></tr>
</table>
</td>
</tr>
<%End If%>
</table>
</body>
</html>
<%
'Object cleanup
If IsObject(objRs) Then
If Not objRs Is Nothing Then
If objRs.State = adStateOpen Then objRs.Close
Set objRs = Nothing
End If
End If
If IsObject(objCn) Then
If Not objCn Is Nothing Then
If objCn.State = adStateOpen Then objCn.Close
Set objCn = Nothing
End If
End If
%>