Abundant Technologies - IT Consulting Experts

 Source Code Library

 Code Details

'put this section on a form with a Datagrid and Command Button Option Explicit Private obj As CData Private Sub cmdConnect_Click() 'Create an instance of the Data Class and bind it to the grid. Set obj = New CData Set DataGrid1.DataSource = obj End Sub 'put this section in a Class Module named CData Option Explicit 'Declare Connection and Recordset at module level. Private cn As ADODB.Connection Private rs As ADODB.Recordset Private Sub Class_GetDataMember(DataMember As String, Data As Object) 'This is the standard method which we use to 'return the data which the class is supplying. Set Data = rs End Sub Private Sub Class_Initialize() Dim s As String 'Establish the connection. Set cn = New ADODB.Connection cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.3.51;" & _ "Data Source=c:\Program Files\DevStudio\VB\nwind.mdb" cn.CursorLocation = adUseClient cn.Open 'Open the recordset. Set rs = New ADODB.Recordset s = "select * from products order by productname" rs.Open s, cn, adOpenStatic, adLockPessimistic End Sub Private Sub Class_Terminate() 'Don't forget to clean up. rs.Close cn.Close Set rs = Nothing Set cn = Nothing End Sub

Mail To: info@3pc.com