Code:
Option Explicit
Private Const mcstrDSNBeg As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
Private Const mcstrDSNEnd As String = ";Persist Security Info=False"
Private Const mcstrPath As String = "C:\DatabaseFile.mdb"
Private Const mcstrDSN As String = mcstrDSNBeg & mcstrPath & mcstrDSNEnd
Private Const mcstrSQLQuery As String = "SELECT * FROM Patient WHERE PatientID=1"
Private Sub Form_Load()
Dim adoConn As ADODB.Connection
Dim adoRS As ADODB.Recordset
Dim adoField As ADODB.Field
Set adoConn = New ADODB.Connection
' OTVORI KONEKCIJU
adoConn.Open mcstrDSN
Set adoRS = New ADODB.Recordset
'OTVORI RECORDSET
adoRS.Open mcstrSQLQuery, adoConn
'ISPISI PODATKE
If adoRS.RecordCount > 0 Then
For Each adoField In adoRS.Fields
Debug.Print adoField.Name, adoField.Value
Next
End If
'ZATVORI I UNISTI OBJEKTE
adoRS.Close
Set adoRS = Nothing
adoConn.Close
Set adoConn = Nothing
End Sub
mcstrDSN ti je connection string i on zavisi od baze sa kojom radis (btw, to nigde nisi naveo). Connection i Recordset objekti sluze za rad sa bazom - preuzimanje podataka, upis novih, modifikacija postojecih, brisanje, .... Ako nisi sa ovim objektima radio pogledaj MSDN.
U bazi (npr. Access) podaci su organizovani u tabelama, a tabele imaju polja.
Ovaj SQL upit
SELECT * FROM Patient WHERE PatientID=1
ce selektovati sve zapise iz tabele Patient gde polje PatientID ima vrednost 1.
[Ovu poruku je menjao mladenovicz dana 15.02.2006. u 00:27 GMT+1]