Accueil > > > TUTORIAL POUR ADODB, ADO
TUTORIAL POUR ADODB, ADO
Information sur la source
Description
ce How To ADODB easy est un tutorial destine a aide les + ou - debutants pour se connecter a une DB en utilisant les commandes ADO ( et pas l'ancien DAO) je l ai ecris en anglais paske je l ai fait pour des amis pas francais et en plus VB c est en anglais
Source
-
- ' Welcome to GuLuCoM's How to ADODB easy.
-
- ' Please tell me what u think about this How To.... gulucom@hotmail.com
-
- ' -> 3 ways to use ADODB :
-
- Dim cn As ADODB.Connection
- Dim rs As ADODB.Recordset
- Dim cmd As ADODB.Command
-
-
- '------------- Open the Database ----------------
- Set cn = New ADODB.Connection
- cn.ConnectionString = " Provider=Microsoft.Jet.OLEDB.4.0;Data Source=TaBaS.mdb;Persist Security Info=False"
- cn.Open
-
- 1.
- '-------------- Create a Command --------------
- Set cmd = New ADODB.Command
- cmd.CommandText = "authors" ' table in the database
- cmd.CommandType = adCmdTable
- cmd.ActiveConnection = cn
-
- '--------------- Create a Recordset --------------------
- Set rs = New ADODB.Recordset
- Set rs.Source = cmd
- rs.Open
-
- 2.
- Set rs = cn.Execute("select * from Table") ' Execute opens the recordset
-
- 3.
-
- Set rs = New ADODB.Recordset
- rs.CursorType = adOpenKeyset
- rs.LockType = adLockOptimistic
- rs.Source = "TbEscort"
- rs.ActiveConnection = cn
- rs.Open
-
-
- ' Now let's play with our recordset (rs)
-
- ' - to add a new row in the recordset :
-
- rs.AddNew
- rs.Fields("First_Name") = x
- rs.Update
-
- ' - to keep the reference of a specific record
- Dim varBKM as Variant
- varBKM = rs.Bookmark
-
- ' - to move in the recordset
- rs.MoveNext
- rs.MoveLast
- ......
-
- ' - to find a specific record
- rs.Find "worker_name LIKE 'r*'"
-
- ' - to filter the recordset
- rs.Filter = "quantity > 30"
-
- ' - to sort the recordset
- rs.Sort = "order_date ASC"
-
- ' - to delete a record
- rs.Delete adAffectCurrent ' -> default
- adAffectGroup ' -> after filter
- adAffectAll
-
- ' - to rexecute the query
- rs.Requery
-
- ' - to update a field in the record
- rs.Update "worker_name", "david"
-
- ' - to save the recordset
- rs.Save "C:/MyRS.adtg", adPersistADTG
- or with ADO 2.1 rs.Save "C:/MyRS.xml", adPersistXML
-
- ' - to open
- rs.Open "C:/MyRS.adtg", , adOpenStatic, adLockOptimistic, adComdFile
-
- ' - NEVER FORGET TO CLOSE
- rs.Close
- cn.Close
- Set rs = Nothing
- Set cn = Nothing
-
-
-
' Welcome to GuLuCoM's How to ADODB easy.
' Please tell me what u think about this How To.... gulucom@hotmail.com
' -> 3 ways to use ADODB :
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim cmd As ADODB.Command
'------------- Open the Database ----------------
Set cn = New ADODB.Connection
cn.ConnectionString = " Provider=Microsoft.Jet.OLEDB.4.0;Data Source=TaBaS.mdb;Persist Security Info=False"
cn.Open
1.
'-------------- Create a Command --------------
Set cmd = New ADODB.Command
cmd.CommandText = "authors" ' table in the database
cmd.CommandType = adCmdTable
cmd.ActiveConnection = cn
'--------------- Create a Recordset --------------------
Set rs = New ADODB.Recordset
Set rs.Source = cmd
rs.Open
2.
Set rs = cn.Execute("select * from Table") ' Execute opens the recordset
3.
Set rs = New ADODB.Recordset
rs.CursorType = adOpenKeyset
rs.LockType = adLockOptimistic
rs.Source = "TbEscort"
rs.ActiveConnection = cn
rs.Open
' Now let's play with our recordset (rs)
' - to add a new row in the recordset :
rs.AddNew
rs.Fields("First_Name") = x
rs.Update
' - to keep the reference of a specific record
Dim varBKM as Variant
varBKM = rs.Bookmark
' - to move in the recordset
rs.MoveNext
rs.MoveLast
......
' - to find a specific record
rs.Find "worker_name LIKE 'r*'"
' - to filter the recordset
rs.Filter = "quantity > 30"
' - to sort the recordset
rs.Sort = "order_date ASC"
' - to delete a record
rs.Delete adAffectCurrent ' -> default
adAffectGroup ' -> after filter
adAffectAll
' - to rexecute the query
rs.Requery
' - to update a field in the record
rs.Update "worker_name", "david"
' - to save the recordset
rs.Save "C:/MyRS.adtg", adPersistADTG
or with ADO 2.1 rs.Save "C:/MyRS.xml", adPersistXML
' - to open
rs.Open "C:/MyRS.adtg", , adOpenStatic, adLockOptimistic, adComdFile
' - NEVER FORGET TO CLOSE
rs.Close
cn.Close
Set rs = Nothing
Set cn = Nothing
Sources du même auteur
Sources de la même categorie
Commentaires et avis
|
Derniers Blogs
[WP7] DYNAMICALLY CHANGE STARTUP PAGE[WP7] DYNAMICALLY CHANGE STARTUP PAGE par KooKiz
Let's say that you want to allow the user to customize the startup page of your application. You can easily change the startup page by editing the 'NavigationPage' attribute in the manifest file. But the manifest cannot be modified once the applicatio...
Cliquez pour lire la suite de l'article par KooKiz SESSION SILVERLIGHT 5 3D : SLIDES ET DEMOSSESSION SILVERLIGHT 5 3D : SLIDES ET DEMOS par Groc
Durant les techdays, j'ai eu le plaisir d'animer une session sur Silverlight 5 et la 3D avec Simon Ferquel. Comme promis, voici nos slides et mes démos (celles avec le viper BSG) ici et là. Pour mémoire, les démos utilisent toutes le viper BSG...
Cliquez pour lire la suite de l'article par Groc [TECHDAYS 2012] SESSION WEBMATRIX 2 : LE COUTEAU SUISSE GRATUIT POUR VOS DéVELOPPEMENTS WEB - SLIDES[TECHDAYS 2012] SESSION WEBMATRIX 2 : LE COUTEAU SUISSE GRATUIT POUR VOS DéVELOPPEMENTS WEB - SLIDES par gpommier
Suite à la session que j'ai présenté sur WebMatrix 2, vous pouvez trouver les slides ici, ainsi que les démos en packages nuget : démos1 et démos2 J'en profite pour remercier chaleureusement tous ceux qui sont venus très nombreux à cette sess...
Cliquez pour lire la suite de l'article par gpommier [SHAREPOINT] LES SESSIONS TECHDAYS 2012.[SHAREPOINT] LES SESSIONS TECHDAYS 2012. par Patrick Guimonet
Voici donc pour ceux qui n'ont pas pu venir, ou ceux qui n'ont pas pu toutes les suivre la liste des sessions SharePoint aux TechDays 2012, que je mettrais à jour dès que les liens des vidéo seront disponibles. Ou ici : http...
Cliquez pour lire la suite de l'article par Patrick Guimonet TECHDAYS PARIS 2012 : SESSION PLEINIèRE JOUR 3TECHDAYS PARIS 2012 : SESSION PLEINIèRE JOUR 3 par ROMELARD Fabrice
Speaker: Bernard Ourghanlian Cette session est comme chaque jour transmise en live par BrainSonic, et j'ai donc suivi cette troisième pleinière par ce moyen sur mon iPad . Elle est dédiée comme chaque année à la mise en perspective de l'é...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice
Forum
LISTER KEYS.KEYLISTER KEYS.KEY par Onin42
Cliquez pour lire la suite par Onin42
Logiciels
Tribler (2012)TRIBLER (2012)Tribler est un client pair à pair (P2P/Peer-to-Peer) open source avec la capacité de regarder des... Cliquez pour télécharger Tribler OneSwarm (2012)ONESWARM (2012)Le peer-to-peer qui protège votre vie privée, c'est OneSwarm.
Ce logiciel de peer-to-peer crypté... Cliquez pour télécharger OneSwarm PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System Easy-Planning (1.0.0.1)EASY-PLANNING (1.0.0.1)Basé sur les mêmes principes que MyPlanning, Easy-Planning permet de créer des plannings sous la ... Cliquez pour télécharger Easy-Planning
|