Problemet är att om jag skriver ut hela med getstring så kommer alla fält jag behöver ut.
då torde det inte vara något fel på sql-frågan. visa koden där du skriver ut informationen med getrows().
12 svar · 239 visningar · startad av erka
Jag har följande kod
SQLStmt = "SELECT Forum.ForumID, ForumReplies.ReplyID, ForumReplies.ReplyPostedBy, ForumReplies.ReplyPostedDate, ForumReplies.ReplyContents, ForumReplies.FkTopicID, ForumTopics.TopicID, ForumTopics.TopicName, ForumTopics.TopicPostedBy, ForumTopics.TopicPostedDate, ForumTopics.TopicContents, ForumTopics.TkForumID, ForumTopics.TopicCountReplies "_
&"FROM (Forum INNER JOIN ForumTopics ON Forum.ForumID = ForumTopics.TkForumID) INNER JOIN ForumReplies ON ForumTopics.TopicID = ForumReplies.FkTopicID "_
& "WHERE (ForumTopics.TopicContents LIKE '%" & strSearch & "%' OR ForumTopics.TopicName LIKE '%" & strSearch & "%') "_
& "AND Forum.ForumID = "& Request.Form("ForumID") &" "_
& "AND ForumTopics.TkForumID = "& Request.Form("ForumID") &" "_
& "OR (ForumReplies.ReplyContents LIKE '%" & strSearch & "%' ) ORDER BY ForumTopics.TopicID DESC"
Det är en sökfunktion som ska söka igenom 2 tabeller som hör till ett forum. Problemet är att om jag skriver ut hela med getstring så kommer alla fält jag behöver ut. Men om jag istället tar en getrows() på den så kommer inte alls de fälten jag behöver med utan de innehåller inte något alls (det som kom med med getstring kommer inte med)
Har jag skrivit helt fel eller ?
Vad jag hela tiden behöver få ut är
- ForumReplies.FkTopicID eller ForumTopics.TopicID
- ForumTopics.TopicContents eller ForumReplies.ReplyContents
- Forum.ForumID
- ForumTopics.TopicPostedBy eller ForumReplies.ReplyPostedBy
Någon som kan hjälpa
Problemet är att om jag skriver ut hela med getstring så kommer alla fält jag behöver ut.
då torde det inte vara något fel på sql-frågan. visa koden där du skriver ut informationen med getrows().
Nej det tycker jag också
jag har denna kod som test nu
SQLStmt = "SELECT Forum.ForumID, ForumReplies.ReplyID, ForumReplies.ReplyPostedBy, ForumReplies.ReplyPostedDate, ForumReplies.ReplyContents, ForumReplies.FkTopicID, ForumTopics.TopicID, ForumTopics.TopicName, ForumTopics.TopicPostedBy, ForumTopics.TopicPostedDate, ForumTopics.TopicContents, ForumTopics.TkForumID, ForumTopics.TopicCountReplies "_
&"FROM (Forum INNER JOIN ForumTopics ON Forum.ForumID = ForumTopics.TkForumID) INNER JOIN ForumReplies ON ForumTopics.TopicID = ForumReplies.FkTopicID "_
& "WHERE (ForumTopics.TopicContents LIKE '%" & strSearch & "%' OR ForumTopics.TopicName LIKE '%" & strSearch & "%') "_
& "AND Forum.ForumID = "& Request.Form("ForumID") &" "_
& "AND ForumTopics.TkForumID = "& Request.Form("ForumID") &" "_
& "OR (ForumReplies.ReplyContents LIKE '%" & strSearch & "%' ) ORDER BY ForumTopics.TopicID DESC"
Set RS = Server.CreateObject("ADODB.Recordset")
RS.Open SQLStmt, Connect, 3, 1
If Rs.EOF Then
Response.Write"The search didn't find any thread containing <b>"& strSearch &"</b>"
Rs.Close
Set RS = Nothing
Connect.Close
Set Connect = Nothing
Else
Rs.Close
Set RS = Nothing
ArrRS = Connect.Execute(SQLStmt).getrows()
For y = 0 to ubound(ArrRS,2)
Response.Write ArrRS(0,y) & "<br>"
Response.Write ArrRS(1,y) & "<br>"
Response.Write ArrRS(2,y) & "<br>"
Response.Write ArrRS(3,y) & "<br>"
Response.Write ArrRS(4,y) & "<br>"
Response.Write ArrRS(5,y) & "<br>"
Response.Write ArrRS(6,y) & "<br>"
Response.Write ArrRS(7,y) & "<br>"
Response.Write ArrRS(8,y) & "<br>"
Response.Write ArrRS(9,y) & "<br>"
Response.Write ArrRS(10,y) & "<br>"
Response.Write ArrRS(11,y) & "<br>"
Response.Write ArrRS(12,y) & "<br>"
Next
Erase ArrRS
Connect.Close
Set Connect = Nothing
End If
Då får jag inga värden i ArrRS: 4,5,6,7,8,9
Men om jag skriver ut denna
SQLStmt = "SELECT Forum.ForumID, ForumReplies.ReplyID, ForumReplies.ReplyPostedBy, ForumReplies.ReplyPostedDate, ForumReplies.ReplyContents, ForumReplies.FkTopicID, ForumTopics.TopicID, ForumTopics.TopicName, ForumTopics.TopicPostedBy, ForumTopics.TopicPostedDate, ForumTopics.TopicContents, ForumTopics.TkForumID, ForumTopics.TopicCountReplies "_
&"FROM (Forum INNER JOIN ForumTopics ON Forum.ForumID = ForumTopics.TkForumID) INNER JOIN ForumReplies ON ForumTopics.TopicID = ForumReplies.FkTopicID "_
& "WHERE (ForumTopics.TopicContents LIKE '%" & strSearch & "%' OR ForumTopics.TopicName LIKE '%" & strSearch & "%') "_
& "AND Forum.ForumID = "& Request.Form("ForumID") &" "_
& "AND ForumTopics.TkForumID = "& Request.Form("ForumID") &" "_
& "OR (ForumReplies.ReplyContents LIKE '%" & strSearch & "%' ) ORDER BY ForumTopics.TopicID DESC"
Set RS = Server.CreateObject("ADODB.Recordset")
RS.Open SQLStmt, Connect, 3, 1
If Rs.EOF Then
Response.Write"The search didn't find any thread containing <b>"& strSearch &"</b>"
Rs.Close
Set RS = Nothing
Connect.Close
Set Connect = Nothing
Else
Response.Write Rs.Getstring
Rs.Close
Set RS = Nothing
Connect.Close
Set Connect = Nothing
End If
så kommer alla värden med, förstår inte vad som är fel
<%
myGetRows = session("listAgendaUsers")
FOR j = 0 to UBound(myGetRows, 2)
FOR i = 0 to UBound(myGetRows, 1)
response.write i & "> " & myGetRows(i, j) & " " & vbCRLF
NEXT
IF NOT j = UBound(myGetRows, 2) THEN response.write "<BR>"
NEXT
%>
Eclpise, vad menar du med den där ?
Se det som en alternativb lösning för...
For y = 0 to ubound(ArrRS,2)
Response.Write ArrRS(0,y) & "<br>"
Response.Write ArrRS(1,y) & "<br>"
Response.Write ArrRS(2,y) & "<br>"
Response.Write ArrRS(3,y) & "<br>"
Response.Write ArrRS(4,y) & "<br>"
Response.Write ArrRS(5,y) & "<br>"
Response.Write ArrRS(6,y) & "<br>"
Response.Write ArrRS(7,y) & "<br>"
Response.Write ArrRS(8,y) & "<br>"
Response.Write ArrRS(9,y) & "<br>"
Response.Write ArrRS(10,y) & "<br>"
Response.Write ArrRS(11,y) & "<br>"
Response.Write ArrRS(12,y) & "<br>"
Next
Jo eclipse det ser jag också, men jag får fortfarande inte ut några värden på fälten 4-9 om jag kör en getrows, men jag får med dem i stringen när jag kör en getstring på samma sqlfråga
Din SQL fråga är över min intellegens så där kan jag inte uttala mig. Men om du kör koden jag gav dig ser du var i arrayen de olika värdena finns. Sen använder du bara dom nummrena i din kod...
Om inte det löser ditt problem så förstår jag inte ditt problem. Koden ovan skriver ut all data som finns i arrayen. Det kan inte vara så att det blir olika om du kör getString eller getRows?
Eclipse, det är det jag heller inte fattat.
Nu gör jag så här
OM JAG SKRIVER UT SQLStmt
SELECT Forum.ForumID, ForumReplies.ReplyID, ForumReplies.ReplyPostedBy, ForumReplies.ReplyPostedDate, ForumReplies.ReplyContents, ForumReplies.FkTopicID, ForumTopics.TopicID, ForumTopics.TopicName, ForumTopics.TopicPostedBy, ForumTopics.TopicPostedDate, ForumTopics.TopicContents, ForumTopics.TkForumID, ForumTopics.TopicCountReplies FROM (Forum INNER JOIN ForumTopics ON Forum.ForumID = ForumTopics.TkForumID) INNER JOIN ForumReplies ON ForumTopics.TopicID = ForumReplies.FkTopicID WHERE (ForumTopics.TopicContents LIKE '%stämmer%' OR ForumTopics.TopicName LIKE '%stämmer%') AND Forum.ForumID = 1 AND ForumTopics.TkForumID = 1 OR (ForumReplies.ReplyContents LIKE '%stämmer%' ) ORDER BY ForumTopics.TopicID DESC
OM JAG SKRIVER UT MED GETSTRING
115 Erik Forsberg 2001-09-05 09:07:15 Det stämmer nog prova att ta en edit på dina inlägg, samt att ta bort dem etc. 52 52 High expectations Peter Granath 2001-09-05 09:00:37 Förväntningarna är stora. 1 1
OM JAG SKRIVER UT MED GETROWS
0. 1
1. 115
2. Erik Forsberg
3. 2001-09-05 09:07:15
4.
5.
6.
7.
8.
9.
10. Förväntningarna är stora.
11. 1
12. 1
KODEN SER NU UT
SQLStmt = "SELECT Forum.ForumID, ForumReplies.ReplyID, ForumReplies.ReplyPostedBy, ForumReplies.ReplyPostedDate, ForumReplies.ReplyContents, ForumReplies.FkTopicID, ForumTopics.TopicID, ForumTopics.TopicName, ForumTopics.TopicPostedBy, ForumTopics.TopicPostedDate, ForumTopics.TopicContents, ForumTopics.TkForumID, ForumTopics.TopicCountReplies "_
&"FROM (Forum INNER JOIN ForumTopics ON Forum.ForumID = ForumTopics.TkForumID) INNER JOIN ForumReplies ON ForumTopics.TopicID = ForumReplies.FkTopicID "_
& "WHERE (ForumTopics.TopicContents LIKE '%" & strSearch & "%' OR ForumTopics.TopicName LIKE '%" & strSearch & "%') "_
& "AND Forum.ForumID = "& Request.Form("ForumID") &" "_
& "AND ForumTopics.TkForumID = "& Request.Form("ForumID") &" "_
& "OR (ForumReplies.ReplyContents LIKE '%" & strSearch & "%' ) ORDER BY ForumTopics.TopicID DESC"
Set RS = Server.CreateObject("ADODB.Recordset")
RS.Open SQLStmt, Connect, 3, 1
If Rs.EOF Then
Response.Write"The search didn't find any thread containing <b>"& strSearch &"</b>"
Rs.Close
Set RS = Nothing
Connect.Close
Set Connect = Nothing
Else
Response.Write SQLStmt & "<br><br><br>"
Response.Write Rs.Getstring & "<br><br><br>"
Rs.Close
Set RS = Nothing
ArrRS = Connect.Execute(SQLStmt).getrows()
For y = 0 to ubound(ArrRS,2)
Response.Write "0. " & ArrRS(0,y) & "<br>"
Response.Write "1. " & ArrRS(1,y) & "<br>"
Response.Write "2. " & ArrRS(2,y) & "<br>"
Response.Write "3. " & ArrRS(3,y) & "<br>"
Response.Write "4. " & ArrRS(4,y) & "<br>"
Response.Write "5. " & ArrRS(5,0) & "<br>"
Response.Write "6. " & ArrRS(6,y) & "<br>"
Response.Write "7. " & ArrRS(7,y) & "<br>"
Response.Write "8. " & ArrRS(8,y) & "<br>"
Response.Write "9. " & ArrRS(9,y) & "<br>"
Response.Write "10. " & ArrRS(10,y) & "<br>"
Response.Write "11. " & ArrRS(11,y) & "<br>"
Response.Write "12. " &ArrRS(12,y) & "<br>"
Next
Erase ArrRS
Connect.Close
Set Connect = Nothing
End If
Blir fundersam, vad som itne fungerar ???
Jag tror att det är något problem med
en PM/MEMO kolumn tex replies.
Prova att lägga den sist i din select.
LarsG , TACK! och ni andra också det fungerade. Varför är det så ?
Nu får jag ut alla utom en, men den behöver jag inte så den kanske man inte ska bry sig om.
SQLStmt = "SELECT ForumReplies.FkTopicID, Forum.ForumID, ForumReplies.ReplyID,ForumReplies.ReplyPostedDate, ForumReplies.ReplyPostedBy, ForumTopics.TkForumID, ForumTopics.TopicCountReplies, ForumTopics.TopicID, ForumTopics.TopicPostedDate, ForumTopics.TopicPostedBy, ForumTopics.TopicContents, ForumReplies.ReplyContents, ForumTopics.TopicName "_
&"FROM (Forum INNER JOIN ForumTopics ON Forum.ForumID = ForumTopics.TkForumID) INNER JOIN ForumReplies ON ForumTopics.TopicID = ForumReplies.FkTopicID "_
& "WHERE (ForumTopics.TopicContents LIKE '%" & strSearch & "%' OR ForumTopics.TopicName LIKE '%" & strSearch & "%') "_
& "AND Forum.ForumID = "& Request.Form("ForumID") &" "_
& "AND ForumTopics.TkForumID = "& Request.Form("ForumID") &" "_
& "OR (ForumReplies.ReplyContents LIKE '%" & strSearch & "%' ) ORDER BY ForumTopics.TopicID DESC"
det är nr 10 jag inte får ut, ForumTopics.TopicContents. Varför inte det kanske du kan svara på. Hur tänker SQLserver här
Är det också en lob (text/image i SQL server PM/MEMO i Access) ?
Alla lob-fält måste lägga sist i select-satsen. Om du har flera i samma tabell så måste man hämta dom i samma ordning som de är definierade i tabellen.
Om du har SQL server så behöver man inte använda text i alla lägen. Oftast så räcker det med en varchar som kan en maxlängd på 8000 byte.
Så om du flyttar den också så ...
Tack LarsG