Méthode GetString ADO
❮ Référence complète de l'objet Recordset
La méthode GetString renvoie le jeu d'enregistrements spécifié sous forme de chaîne. Cette méthode peut être utilisée pour remplir des tableaux HTML dans des fichiers ASP.
Syntaxe
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 |
Exemple
Pour créer un tableau HTML avec les données d'un jeu d'enregistrements, nous n'avons besoin d'utiliser que trois des paramètres ci-dessus :
- coldel - le code HTML à utiliser comme séparateur de colonnes
- rowdel - le code HTML à utiliser comme séparateur de lignes
- NullExpr - le code HTML à utiliser si une colonne est NULL
Remarque : La méthode GetString() est une fonctionnalité ADO 2.0. Vous pouvez télécharger ADO 2.0 à l' adresse http://www.microsoft.com/data/download.htm .
Exemple
Dans l'exemple suivant, nous utiliserons la méthode GetString() pour conserver le jeu d'enregistrements sous forme de chaîne :
<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>
Valeurs StringFormatEnumStringFormatEnum Values
Constant | Value | Description |
---|---|---|
adClipString | 2 | Delimits rows by the rowdel parameter, columns by the coldel parameter, and null values by the nullexpr parameter |
❮ Référence complète de l'objet Recordset