R
Roar
Hi!
I have got 1 access 2000 DB, one simple search form, and 3 .asp pages (one
for deleting a record, one for inserting a record and one for listing
searchresults). Deleting records works fine, Inserting records works fine,
but my headache is the searchform.. Whatever i type in the searchbox (sok),
the result is all database entries, not just the entries matching the term
I'm asking for. No error code is given.The code for the search is inserted
below. As you may see, this source is not written by me but is modified to
my needs. I'm guessing that something in this code overrules my SQL
statement.
Does anyone see any obvious errors in my code? I have tried with different
SQL statements (as seen below)
In advance
Thnx
<%
' Declaring variables
Dim rs, data_source, no, sok, sql_select
' A Function to check if some field entered by user is empty
Function ChkString(string)
' If string = "" Then string = " "
' ChkString = Replace(string, "'", "''")
End Function
' Receiving values from Form
sok = ChkString(Request.Form("sok"))
no = 0
data_source = "Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=c:\www\myserver\db\links.mdb" '## MS Access 2000
'sql_select = "select (program, link, beskrivelse) from links where
values like ('" & sok & "') "
'sql_select = "select * from links where values like sok "
sql_select = "select * from links (program, links, beskrivelse) where
program like '%" & sok & "%' or links like '%" & sok & "%' or beskrivelse
like '%" & sok & "%'"
' Creating Recordset Object and opening the database
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open "links", data_source
' Looping through the records to show all of them
While Not rs.EOF %>
<form action="del.asp" method="post">
<tr>
<td><%=rs("program") %></td>
<td><%=rs("link") %></td>
<td><%=rs("beskrivelse") %></td>
<td><input type="hidden" name="id" value="<%=rs("id")%>"> <input
type="submit" value="SLETT"></form></td>
</tr>
<%
no = no + 1
rs.MoveNext
Wend
' Done. Now close the Recordset
rs.Close
Set rs = Nothing
%>
<tr>
<td height=10 valign="top" width="160"></td>
<td height=10 valign="top" width="273"></td>
<td height=10 valign="top" width="272"><b>Totalt antall program</b> :
<%=no %></td>
<td height=10 valign="top" width=93></td>
</tr>
</table>
<p>Tilbake til <a href="form_sok.htm">Søkeskjemaet</a></p>
</body>
</html>
I have got 1 access 2000 DB, one simple search form, and 3 .asp pages (one
for deleting a record, one for inserting a record and one for listing
searchresults). Deleting records works fine, Inserting records works fine,
but my headache is the searchform.. Whatever i type in the searchbox (sok),
the result is all database entries, not just the entries matching the term
I'm asking for. No error code is given.The code for the search is inserted
below. As you may see, this source is not written by me but is modified to
my needs. I'm guessing that something in this code overrules my SQL
statement.
Does anyone see any obvious errors in my code? I have tried with different
SQL statements (as seen below)
In advance
Thnx
<%
' Declaring variables
Dim rs, data_source, no, sok, sql_select
' A Function to check if some field entered by user is empty
Function ChkString(string)
' If string = "" Then string = " "
' ChkString = Replace(string, "'", "''")
End Function
' Receiving values from Form
sok = ChkString(Request.Form("sok"))
no = 0
data_source = "Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=c:\www\myserver\db\links.mdb" '## MS Access 2000
'sql_select = "select (program, link, beskrivelse) from links where
values like ('" & sok & "') "
'sql_select = "select * from links where values like sok "
sql_select = "select * from links (program, links, beskrivelse) where
program like '%" & sok & "%' or links like '%" & sok & "%' or beskrivelse
like '%" & sok & "%'"
' Creating Recordset Object and opening the database
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open "links", data_source
' Looping through the records to show all of them
While Not rs.EOF %>
<form action="del.asp" method="post">
<tr>
<td><%=rs("program") %></td>
<td><%=rs("link") %></td>
<td><%=rs("beskrivelse") %></td>
<td><input type="hidden" name="id" value="<%=rs("id")%>"> <input
type="submit" value="SLETT"></form></td>
</tr>
<%
no = no + 1
rs.MoveNext
Wend
' Done. Now close the Recordset
rs.Close
Set rs = Nothing
%>
<tr>
<td height=10 valign="top" width="160"></td>
<td height=10 valign="top" width="273"></td>
<td height=10 valign="top" width="272"><b>Totalt antall program</b> :
<%=no %></td>
<td height=10 valign="top" width=93></td>
</tr>
</table>
<p>Tilbake til <a href="form_sok.htm">Søkeskjemaet</a></p>
</body>
</html>