Phương pháp ADO GetString
❮ Tham chiếu đối tượng tập bản ghi hoàn chỉnh
Phương thức GetString trả về Tập bản ghi được chỉ định dưới dạng một chuỗi. Phương pháp này có thể được sử dụng để điền các bảng HTML trong các tệp ASP.
Cú pháp
Set str=objRecordset.GetString(format,n,coldel,rowdel,nullexpr)
Parameter | Description |
---|---|
format | Optional. A StringFormatEnum value that specifies the format when retrieving a Recordset as a string |
n |
Optional. The number of rows to be converted in the Recordset |
coldel | Optional. If format is set to adClipString it is a column delimiter. Otherwise it is the tab character |
rowdel | Optional. If format is set to adClipString it is a row delimiter. Otherwise it is the carriage return character |
nullexpr | Optional. If format is set to adClipString it is an expression used instead of a null value. Otherwise it is an empty string |
Thí dụ
Để tạo một bảng HTML với dữ liệu từ một tập bản ghi, chúng ta chỉ cần sử dụng ba tham số ở trên:
- coldel - HTML để sử dụng làm dấu phân tách cột
- rowdel - HTML để sử dụng làm dấu phân tách hàng
- NullExpr - HTML để sử dụng nếu một cột là NULL
Lưu ý: Phương thức GetString () là một tính năng ADO 2.0. Bạn có thể tải xuống ADO 2.0 tại http://www.microsoft.com/data/download.htm .
Thí dụ
Trong ví dụ sau, chúng tôi sẽ sử dụng phương thức GetString () để giữ tập bản ghi dưới dạng một chuỗi:
<html>
<body>
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "c:/webdata/northwind.mdb"
set rs = Server.CreateObject("ADODB.recordset")
rs.Open "SELECT Companyname, Contactname FROM Customers", conn
str=rs.GetString(,,"</td><td>","</td></tr><tr><td>"," ")
%>
<table border="1" width="100%">
<tr>
<td><%Response.Write(str)%></td>
</tr>
</table>
<%
rs.close
conn.close
set rs = Nothing
set conn = Nothing
%>
</body>
</html>
Giá trị StringFormatEnum
Constant | Value | Description |
---|---|---|
adClipString | 2 | Delimits rows by the rowdel parameter, columns by the coldel parameter, and null values by the nullexpr parameter |
❮ Tham chiếu đối tượng tập bản ghi hoàn chỉnh