---
title: "SQL problem i sökfunktion"
type: "forum-thread"
url: "https://www.webforum.nu/amne/asp/11036-sql-problem-i-sökfunktion"
topic: "ASP"
topic_url: "https://www.webforum.nu/amne/asp"
author: "Pace"
published: "2001-08-08T15:14:00.000Z"
updated: "2001-08-09T21:48:00.000Z"
replies: 4
views: 196
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/asp/11036-sql-problem-i-sökfunktion"
---

# SQL problem i sökfunktion

## #1 — Pace, 2001-08-08T15:14Z

Sökfunktion till forum.

Fel:

```
Item cannot be found in the collection corresponding to the requested name or ordinal.
```

```
SELECT Forum.*, Reply.*, Topics.* FROM (Forum LEFT JOIN Topics ON Forum.Forum_ID = Topics.Forum_id) LEFT JOIN Reply ON Topics.Topic_ID = Reply.Topic_ID WHERE (Forum.F_Description LIKE '%hej%' OR Reply.R_Message Like '%hej%' OR Topics.T_Message LIKE '%hej%' ) ORDER BY topics.topic_id
```

Felet uppstår när jag försöker hämta följande rs: rs("topic_id")

Permalänk: https://www.webforum.nu/p/11036

## #2 — LarsG, 2001-08-08T15:54Z

Det verkar ju skumt. Du får nog visa mer kod, du kanske blandar ihop recordseten?

Permalänk: https://www.webforum.nu/p/283303

## #3 — Pace, 2001-08-09T19:13Z

Okej, skickar med hela faderullan :)

```
	keywords = Split(dbSecure(Request.Form("search")), " ")
	keycnt = Ubound(keywords)
	
	SQL ="SELECT  Forum.*, Reply.*, Topics.* FROM (Forum LEFT JOIN Topics "
	SQL = SQL & "ON Forum.Forum_ID = Topics.Forum_id) LEFT JOIN Reply ON Topics.Topic_ID = Reply.Topic_ID "
	SQL = SQL & "WHERE "
	
	if Request.Form("forum") <> 0 then
		SQL = SQL & "Forum.Forum_ID = " & Request.Form("forum") & " AND "
	End If
	
	SQL = SQL & "("
	
	if Request.Form("searchdate") <> 0 then
		dt = cint(Request.Form("searchdate"))
		SQL = SQL & "T_date > #" & dateadd("d", -dt, now) & "#) AND ("
	End if

	cnt = 0
	For Each word In keywords
		SQL = SQL & "Forum.F_Description LIKE '%" & word & "%'  OR Reply.R_Message LIKE '%" & _
		word & "%'  OR  Topics.T_Message LIKE '%" & _
		word & "%' "
		If cnt < keycnt Then SQL = SQL & Request.Form("andor") 
		cnt = cnt + 1
	Next 
	
	SQL = SQL & ") ORDER BY topics.topic_id"

	
	mypage = Request("whichpage")
	If mypage = "" then mypage = 1

		'************************************************
		' SQL:en genererar fel ibland om man söker på vissa ord!!
		response.write "<FONT FACE=""courier new"" SIZE=2>" & SQL  & "<P>"

	Set Connection = Server.CreateObject("ADODB.Connection")
	Connection.Open ConnString
	Set rs = Connection.Execute(SQL)

	If rs.Eof or rs.Bof then
		Response.Write "<FONT FACE=""" & DefaultFontFace & """ SIZE=2>" & _
		"<DIV ALIGN=""center"">Inga träffar hittades.</CENTER></FONT>"
	Else
		Response.Write "<FONT FACE=""" & DefaultFontFace & """ SIZE=2>" & _
		"Visar sökresultat.</FONT>"
	%>
		   rec_id = ""
		   Do until rs.Eof
		      [red]If rec_id <> rs("topic_id") Then
				Response.Write "<TD BGCOLOR='...
				"<font color='" & ForumLinkColor...
				"<td bgcolor='" & ...
				"<td bgcolor='" & ForumCellColor & "' align=...
				"</tr>"
			  End if 
			  rec_id = rs("topic_id")
			  rs.MoveNext
			Loop

		' Rensa upp
		rs.Close
		Connection.Close
		Set rs = nothing
		Set Connection = nothing
```

\[r\] Den röda är felraden.
\[r2\] Lite väl långa rader kanske =)

Permalänk: https://www.webforum.nu/p/283304

## #4 — LarsG, 2001-08-09T20:53Z

Jag förstår inte riktigt. Det borde till och med finnas två förekomster av den kolumnen i recordsetet (borde inte ha någon betydelse). 

Om du skriver

```

  select * from ...
```

i stället? Blir det bättre?

Du kan ju också testa med att namnge fälten

```
select topic.topic_id as topic_id, 
       forum.description as ...
```

Tyvärr, så har jag ingen förklaring om vad som är problemet.

Permalänk: https://www.webforum.nu/p/283305

## #5 — Pace, 2001-08-09T21:48Z

He, inget av det funkade... har aldrig varit med om något sånt här innan, kanske är det databasen som spökar?

Permalänk: https://www.webforum.nu/p/283306

---

Tråden på webben: https://www.webforum.nu/amne/asp/11036-sql-problem-i-sökfunktion
