Chức năng: Trả lại mảng hai chiều miêu tả kết quả câu lệnh SQL lên DB
Ngôn ngữ: asp - Nhóm: database
CÚ PHÁP
array = RecSet(connstring, SQL)
Trả lại mảng hai chiều miêu tả kết quả một câu lệnh SQL lên DB.
Các đối số:
connstring: đường dẫn đến DB tồn tại.
SQL: Câu truy vấn SQL.
Nếu không có bản ghi nào, hàm trả về giá trị null.
VÍ DỤ
<%
dim ar, i, j, cn, strSQL
cn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & server.mappath("/database/mydata.mdb") & ";"
strSQL = "SELECT exampleName, exampleDesc FROM examples ORDER BY exampleName;"
ar = RecSet(cn, strSQL)
If IsNull(ar) Then
'--- no results found
response.write "<P STYLE=""font-size:10pt;"">" & vbCrLf
response.write "No Results Found!" & vbCrLf
response.write "</P>" & vbCrLf
Else
response.write "<P STYLE=""font-size:10pt;"">" & vbCrLf
For j = 0 to ubound(ar, 2)
For i = 0 to ubound(ar, 1)
response.write ar(i, j) & vbCrLf
response.write "<BR>" & vbCrLf
Next
response.write "<BR>" & vbCrLf
Next
response.write "</P>" & vbCrLf
End If
%>
ASP Code
<%
Private Function RecSet(byVal connstring, byVal SQL)
Dim DebugRs, Tmp
Set DebugRs = Server.CreateObject("ADODB.Recordset")
With DebugRs
.CursorType = 3 '--- adOpenStatic
.CursorLocation = 2 '--- adUseServer
.LockType = 1 '--- adLockReadOnly
.ActiveConnection = connstring
.Source = SQL
.Open
If .BOF then
Tmp = Null
Else
Tmp = .GetRows()
End If
.Close
End With
Set DebugRs = Nothing
RecSet = Tmp
End Function '--- RecSet
%>