- <% @Language = VBSCRIPT %>
-
- <% Option Explicit %>
-
- <!--#include virtual="/adovbs.inc"-->
-
- <%
-
- 'Crée une connexion à notre base de données Produits
-
- Dim objConn
-
- Set objConn = Server.CreateObject("ADODB.Connection")
-
- objConn.ConnectionString = "DSN=BDDProduits"
-
- objConn.Open
-
- 'Crée une instance d'objet recordset, objRS
-
- Dim objRS
-
- Set objRS = Server.CreateObject("ADODB.Recordset")
-
- 'Ouvre le Recordset avec un curseur Keyset
-
- objRS.Open "Produits", objConn, adOpenKeyset, , adCmdTable
-
- 'Affiche le contenu de la table Produits du dernier
-
- 'enregistrement au premier... Donc, pour commencer, nous devons passer
-
- 'au dernier enregistrement
-
- objRS.MoveLast
-
- 'Nous devons maintenant passer du dernier au premier
-
- Do While Not objRS.BOF
-
- Response.Write "<BR>" & objRS("Nom") & " - " & _
-
- FormatCurrency(objRS("Prix"))
-
- 'Passe au précédent enregistrement
-
- objRS.MovePrevious
-
- Loop
-
- 'Nettoyage !
-
- objRS.Close
-
- Set objRS = Nothing
-
- objConn.Close
-
- Set objConn = Nothing
-
- %>
-
- 2. Créez implicitement un objet Recordset à l'aide de la méthode Execute de l'objet Connection. Cette méthode doit lancer une requête SQL.
-
- <% @Language = VBSCRIPT %>
-
- <% Option Explicit %>
-
- <!--#include virtual="/adovbs.inc"-->
-
- <%
-
- 'Crée une connexion à notre base de données Produits
-
- Dim objConn
-
- Set objConn = Server.CreateObject("ADODB.Connection")
-
- objConn.ConnectionString = "DSN=BDDProduits"
-
- objConn.Open
-
- 'Crée une chaîne SQL
-
- Dim strSQL
-
- strSQL = "SELECT Nom,Prix FROM Produits ORDER BY Prix"
-
- 'Crée une instance d'objet recordset, objRS
-
- Dim objRS
-
- Set objRS = objConn.Execute(strSQL)
-
- 'Affiche le contenu du Recordset objRS
-
- Do While Not objRS.EOF
-
- Response.Write "<BR>" & objRS("Nom") & " - " & _
-
- FormatCurrency(objRS("Prix"))
-
- 'Passe au prochain enregistrement
-
- objRS.MoveNext
-
- Loop
-
- 'Nettoyage !
-
- objRS.Close
-
- Set objRS = Nothing
-
- objConn.Close
-
- Set objConn = Nothing
-
- %>
-
- 3. Créez implicitement un objet Recordset en utilisant la méthode Execute de l'objet Command. La méthode Execute doit être utilisée pour extraire le contenu de la table de la base de données.
-
- <% @Language = VBSCRIPT %>
-
- <% Option Explicit %>
-
- <!--#include virtual="/adovbs.inc"-->
-
- <%
-
- 'Crée une connexion à notre base de données Produits
-
- Dim objConn
-
- Set objConn = Server.CreateObject("ADODB.Connection")
-
- objConn.ConnectionString = "DSN=BDDProduits"
-
- objConn.Open
-
- 'Crée l'objet command
-
- Dim objCommand
-
- Set objCommand = Server.CreateObject("ADODB.Command")
-
- 'Définit les propriétés de l'objet command
-
- objCommand.CommandText = "Produits"
-
- objCommand.ActiveConnection = objConn
-
- objCommand.CommandType = adCmdTable
-
- 'Crée une instance d'objet implicite recordset, objRS
-
- Dim objRS
-
- Set objRS = objCommand.Execute
-
- 'Affiche le contenu du Recordset objRS
-
- Do While Not objRS.EOF
-
- Response.Write "<BR>" & objRS("Nom") & " - " & _
-
- FormatCurrency(objRS("Prix"))
-
- 'Passe à l'enregistrement suivant
-
- objRS.MoveNext
-
- Loop
-
- 'Nettoyage !
-
- objRS.Close
-
- Set objRS = Nothing
-
- objConn.Close
-
- Set objConn = Nothing
-
- %>
<% @Language = VBSCRIPT %>
<% Option Explicit %>
<!--#include virtual="/adovbs.inc"-->
<%
'Crée une connexion à notre base de données Produits
Dim objConn
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.ConnectionString = "DSN=BDDProduits"
objConn.Open
'Crée une instance d'objet recordset, objRS
Dim objRS
Set objRS = Server.CreateObject("ADODB.Recordset")
'Ouvre le Recordset avec un curseur Keyset
objRS.Open "Produits", objConn, adOpenKeyset, , adCmdTable
'Affiche le contenu de la table Produits du dernier
'enregistrement au premier... Donc, pour commencer, nous devons passer
'au dernier enregistrement
objRS.MoveLast
'Nous devons maintenant passer du dernier au premier
Do While Not objRS.BOF
Response.Write "<BR>" & objRS("Nom") & " - " & _
FormatCurrency(objRS("Prix"))
'Passe au précédent enregistrement
objRS.MovePrevious
Loop
'Nettoyage !
objRS.Close
Set objRS = Nothing
objConn.Close
Set objConn = Nothing
%>
2. Créez implicitement un objet Recordset à l'aide de la méthode Execute de l'objet Connection. Cette méthode doit lancer une requête SQL.
<% @Language = VBSCRIPT %>
<% Option Explicit %>
<!--#include virtual="/adovbs.inc"-->
<%
'Crée une connexion à notre base de données Produits
Dim objConn
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.ConnectionString = "DSN=BDDProduits"
objConn.Open
'Crée une chaîne SQL
Dim strSQL
strSQL = "SELECT Nom,Prix FROM Produits ORDER BY Prix"
'Crée une instance d'objet recordset, objRS
Dim objRS
Set objRS = objConn.Execute(strSQL)
'Affiche le contenu du Recordset objRS
Do While Not objRS.EOF
Response.Write "<BR>" & objRS("Nom") & " - " & _
FormatCurrency(objRS("Prix"))
'Passe au prochain enregistrement
objRS.MoveNext
Loop
'Nettoyage !
objRS.Close
Set objRS = Nothing
objConn.Close
Set objConn = Nothing
%>
3. Créez implicitement un objet Recordset en utilisant la méthode Execute de l'objet Command. La méthode Execute doit être utilisée pour extraire le contenu de la table de la base de données.
<% @Language = VBSCRIPT %>
<% Option Explicit %>
<!--#include virtual="/adovbs.inc"-->
<%
'Crée une connexion à notre base de données Produits
Dim objConn
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.ConnectionString = "DSN=BDDProduits"
objConn.Open
'Crée l'objet command
Dim objCommand
Set objCommand = Server.CreateObject("ADODB.Command")
'Définit les propriétés de l'objet command
objCommand.CommandText = "Produits"
objCommand.ActiveConnection = objConn
objCommand.CommandType = adCmdTable
'Crée une instance d'objet implicite recordset, objRS
Dim objRS
Set objRS = objCommand.Execute
'Affiche le contenu du Recordset objRS
Do While Not objRS.EOF
Response.Write "<BR>" & objRS("Nom") & " - " & _
FormatCurrency(objRS("Prix"))
'Passe à l'enregistrement suivant
objRS.MoveNext
Loop
'Nettoyage !
objRS.Close
Set objRS = Nothing
objConn.Close
Set objConn = Nothing
%>