首页 | 培训 | 求学 | 参考 | 教师 | 教材 | 学校 | 招聘 | 租房 | 旅游ASKEDU.com  


培训指南—ASKEDU.com

返回 | 主页


创建服务器端的ASP搜索组件(7)



[摘要]
在这里我使用的处理是为了示范,而且因为它在转入命令之前用二进制存储代码,这样可以提高数据库处理的速度:
’~~~~~ Open the connection with a data source name
objConn.Open "SearchExampleDSN"
’~~~~~ Begin the transaction (onl...

在这里我使用的处理是为了示范,而且因为它在转入命令之前用二进制存储代码,这样可以提高数据库处理的速度:
’~~~~~ Open the connection with a data source name
objConn.Open "SearchExampleDSN"
’~~~~~ Begin the transaction (only for speed in this case)
objConn.BeginTrans
’~~~~~ Store the SQL command in a string
strSQL = "SELECT Title, Text, URL FROM SearchTable"
’~~~~~ Set the Command object to the SQL string
objCmd.CommandText = strSQL
’~~~~~ indicate that the command is a SQL string (for speed)
objCmd.CommandType = adCmdText
’~~~~~ Set the Connection object to the Command object
Set objCmd.ActiveConnection = objConn
  一旦我们用命令对象得到了所需要的打开记录集的连接,我们就设置:
’~~~~~Open Recordset with the above Command settings
recSearch.Open objCmd
  在继续进行搜索之前,需要验证我们确实向搜索返回了一些记录。如果没有返回记录,记录集就既是在开头也是在结尾:
If recSearch.EOF And recSearch.BOF Then
’~~~~No records were returned by the SQL
GetRecords = 0
  但是,如果SQL声明返回了一些记录,就需要设置一些变量确保记录集处在开头:
Else
’~~~~Initialize Procedural Variables
intRecordsMatched = 0
intRecordsDisplayed = 0
intRecordsSearched = 0
mintSearchStart = CInt(mobjRequest.QueryString("Start"))
If mintSearchStart = 0 Then mintSearchStart = 1
recSearch.MoveFirst
  随着不同的整数计数器的增加,我们在记录集中循环,并将数据库中的标题、文本、URL数据存储在本地字符串变量中:
’~~~~Loop through the recordset
Do While Not recSearch.EOF
’Increment the total number of records to be searched
intRecordsSearched = intRecordsSearched + 1
’~~~~~ Store the database field data in temparary strings
strTitleHold = recSearch.Fields("Title")
strTextHold = recSearch.Fields("Text")
strURLhold = recSearch.Fields("URL")
  连接文本和标题字符串后,从头至尾搜索字符串,首先将字符串变成大写字母,然后把我们的查询字符串片段也变成大写字母进行搜索:
’~~~~Concatenate the Title and URL into a String to Search
strSearchHold = strTitleHold & strTextHold
’~~~~~ Determine if the database record meets the visitors query
If InStr(UCase(strSearchHold), _
UCase(mobjRequest.QueryString("Src"))) Then
’~~~~Increment the number of records that match the visitor’s query
intRecordsMatched = intRecordsMatched + 1
  如果我们的记录数据包含了查询字符串,就必须要确定它是否在导航列表界限范围内。这是一点技巧,
’Determine if records are within Start/Stop display range
If intRecordsMatched >= mintSearchStart And _
intRecordsDisplayed < mintMaxSearchReturn Then
  这个声明使用了mintSearchStart 变量,导航条把它作为一个查询字符串来获取,然后查看一下列表页是否达到了它的最大容量,而这个最大容量是由mintMaxSearchReturn变量决定的。如果通过了测试,就将控制传递给动态数列声明。
  每次传递动态数列保存内容之后,调整其大小。
’~~~~Increment number of records to display
intRecordsDisplayed = intRecordsDisplayed + 1
’~~~~Store Title in title array
ReDim Preserve astrTitleArray(intRecordsDisplayed)
astrTitleArray(intRecordsDisplayed) = strTitleHold
’~~~~Store URL in URL array
Redim Preserve astrURLArray(intRecordsDisplayed)
astrURLArray(intRecordsDisplayed) = strURLHold
End If
End If


其它培训参考信息:
创建服务器端的ASP搜索组件(6)
创建服务器端的ASP搜索组件(5)
创建服务器端的ASP搜索组件(4)
创建服务器端的ASP搜索组件(3)
创建服务器端的ASP搜索组件(2)
创建服务器端的ASP搜索组件(1)
三条语句搞定路径
使用速度更快的OLEDB取代ODBC连结



信息来自互联网,敬请核实,谨慎使用



 




  中国 | Worldwide: United States United Kingdom Australia Canada India | Travel AgencyASKEDU.com