Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL statements in ASP page

Status
Not open for further replies.

david7777777777

Programmer
Sep 26, 2001
417
US
I'm using SQL 2000 and InterDev 6. I am making a simple "KnowledgeBase" database to hold articles, just like Microsoft's knowledge base, only I hope to make mine easy to use. ;-) I'm now making the ASP pages that will serve as the user interface.

Here is my SQL table:

tbl_Articles
ArticleID smallint(2) PK
ArticleTitle char(50)
ArticleBody text(16)
Category char(30)
Keywords text(16)

Here are my ASP page components:

rsArticles (Recordset)
txtKeywords (user will type his keyword(s)into this textbox)
btnGo (this Go button is pressed to initiate the search)
Grid1 (Grid that will display the results)

I can't figure out, after days of searching and reading now, how to get the search parameter (what the user types into txtKeywords) into the SQL statement that will search the database.

I've tried including the SQL statement in the Recordset and I've tried doing it in script using the setSQLText method. I've never used the setSQLText method before so I might be doing it wrong. But it seems straight forward enough.

Any help, including pointing me to some online resources for this type of stuff, is greatly appreciated. Thanks.




 
I'm not sure I am answering your question, but this is how I would select from the database based on keywords and return the matching values:


<%
dim strKeywords, tmpArray, intCount, strInsert, strSQL
dim conn, rsArticles

'make & open connection to database


strKeywords = Request.form(&quot;txtKeywords&quot;)
tmpArray = Split(strKeywords,&quot;,&quot;) 'place keywords in array

intCount=0
strInsert=&quot;&quot;
'build comma delimited, quoted list
for intCount=0 to UBound(tmpArray)
if Len(strInsert)=0 then
strList=&quot;'&quot; & tmpArray(intCount) & &quot;'&quot;
else
strList = strInsert & &quot;,'&quot; & tmpArray(intCount) & &quot;'&quot;
end if
next

'build SQL statement
strSQL = &quot;SELECT * From tbl_Articles A&quot;
strSQL = strSQL & &quot; WHERE A.Keywords IN (&quot; & strList & &quot;)&quot;

Set rs = Server.CreateObject(&quot;ADODB.Recordset&quot;)
Set rs = conn.Execute(strSQL)

if NOT rs.eof then
'process matching records
else
'no matching records
Response.write(&quot;No matching records found.<br>&quot;)
end if

%>

I hope this at least gives you a starting point. I don't guarantee no errors, as this is just written off the top of my head :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top