PDA

View Full Version : [ASP] Ricerca doppioni


Giullare
04-04-2008, 11:52
Scusate ragazzi devo fare un programmino in asp che effettua le seguente operazioni:

1) L'utente inserisce un numero
2) Il programma controlla se il numero inserito è già presente nel database
3) In caso positivo avverte che il numero e già esistente e si blocca
4) In caso negativo inserisce il nuovo numero nel database

Io pensavo a qualcosa del genere, ma c'è un errore nella stringa If rstSearch.Fields("protocollo").Value="5566" then response.write "C'è : ".

Come posso fare? Grazie mille!

<%
if session("admin") <> "" then
if request.form("submit") <> "" then
strDBPath = Server.MapPath("../mdb-database/protocolli.mdb")
Set cnnSearch = Server.CreateObject("ADODB.Connection")
cnnSearch.Open = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath
strSQL = "SELECT protocollo, note, ID " _
& "FROM calendarEvent " _
& "WHERE protocollo LIKE '%" & Replace(strSearch, "'", "''") & "%' " _
& "ORDER BY protocollo;"
Set rstSearch = cnnSearch.Execute(strSQL)
If rstSearch.Fields("protocollo").Value="5566" then response.write "C'è : "
else %>
<body style="font-family: Verdana; font-size: 12 pt">

<form action="add.asp" name="Go" method="post">
<h2 align="center">Aggiungi</h2>
<p align="center"><a href="login.asp">
<span style="text-decoration: none; font-weight:700"><font size="2">Torna nella pagina principale</font></span></a></p>
<p align="center">&nbsp;</p>
<div align="center">
<center>
<table width="698" border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111">
<tr>
<td width="317" style="height: 40px"><font size="2">&nbsp;&nbsp; Protocollo n</font></td>
<td width="381" style="height: 40px">
&nbsp;<input name="protocollo" type="text" id="protocollo" maxlength="100" size="20"></td>
</tr>
<span style="text-decoration: none; font-weight:700">
<tr>
<td width="317" style="height: 111px"><font size="2">&nbsp;&nbsp; Note</font><p>
&nbsp;</td>
<td width="381" style="height: 111px">&nbsp;<textarea name="note" cols="44" rows="5" id="note"></textarea></td>
</tr>
<tr>
<td colspan="2" width="680" height="35"><div align="center">
<input type="submit" name="Submit" value="Clicca per aggiungere">
</div></td>
</tr>
</table>

</center>
</div>
</form>
<% end if
conn.close
else %>
<!--#include file="login.asp"-->
<% end if %>