View Single Post
Old 05-09-2011, 10:02   #3
Luc72
Senior Member
 
L'Avatar di Luc72
 
Iscritto dal: Sep 2006
Messaggi: 335
Un esempio veloce (nei riferimenti devi selezionare ADO.NET):

Dim SQL_Database As New ADODB.Connection
Dim SQL_RecordSet As New ADODB.Recordset
Dim SQL_Command As New ADODB.Command

SQL_Database.ConnectionTimeout = 30
SQL_Database.CommandTimeout = 0
SQL_Database.CursorLocation = ADODB.CursorLocationEnum.adUseClient

SQL_Command.CommandTimeout = 0
SQL_Command.CommandType = ADODB.CommandTypeEnum.adCmdText

SQL_Database.Open("Provider=SQLOLEDB.1;Password=**password del database**;Persist Security Info=True;User ID=**utente database**;Initial Catalog=**nome db**;Data Source=**path del file mdb**;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096")

SQL_Command.ActiveConnection = SQL_Database

SQL_Command.CommandText = ** query da eseguire **

SQL_RecordSet.LockType = ADODB.LockTypeEnum.adLockOptimistic
SQL_RecordSet.Open(SQL_Command)

nel commandtext puoi utilizzare qualsiasi sintassi SQL:

SELECT * FROM Utenti WHERE Utente='DYLAN' <-- per selezionare i record

DELETE FROM Utenti WHERE Utente='DYLAN' <-- per cancellare

INSERT INTO Utenti (Utente, Nome) VALUES ('DYLAN','DYLAN DOG')

UPDATE Utenti SET Nome='DYLAN DOG 2' WHERE Utente='DYLAN' <-- per aggiornare

per leggere i record:
Dim t_Valore = SQL_RecordSet("Nome").Value

per passare al record successivo:
SQL_RecordSet.MoveNext()

per controllare se sono finiti i record:
SQL_RecordSet.EOF() (se ritorna true sono finiti)
Luc72 è offline   Rispondi citando il messaggio o parte di esso