"dsn=employees;uid=sa;pwd=;"
FetchEmploymentStatusList = rs.GetRows() ' 将记录集用数组返回
rs.Close
Set rs = Nothing
End Function
A further refinement of the above might be to cache the HTML for the
list, rather than the array. Here’s a simple sample:
' 获取记录集,返回HTML Option列表
Function FetchEmploymentStatusList
Dim rs, fldName, s
Set rs = CreateObject("ADODB.Recordset")
rs.Open "select StatusName, StatusID from EmployeeStatus", _
"dsn=employees;uid=sa;pwd=;"
s = "<select name=""EmploymentStatus">" & vbCrLf
Set fldName = rs.Fields("StatusName") ' ADO 字段绑定
Do Until rs.EOF
s = s & " <option>" & fldName & "</option>" & vbCrLf
rs.MoveNext
Loop
s = s & "</select>" & vbCrLf
rs.Close
Set rs = Nothing ' 释放rs
FetchEmploymentStatusList = s ' 用字符串方式返回数据
End Function
在正确情况下,你可以将ADO记录集本身缓存在Application或Session范围,但必须满足下面两个条件: .ADO必须被标记为自由线程模型(Free-threaded) .必须使用无连接记录集
| 对此文章发表了评论 |
