Type | Description | |||
Object | An Object that defines the control's data. Currently, the control supports ADO.Recordset, ADODB.Recordset objects, DAO recordsets |
The following VB sample binds the "Employees" table in the "NWIND.MDB" database to the component, using an ADODB recordset:
Dim rs As Object, strNWIND As String strNWIND = "D:\Program Files\Microsoft Visual Studio\VB98\NWIND.MDB" Set rs = CreateObject("ADODB.Recordset") rs.Open "Employees", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & strNWIND, 3, 3 ' Opens the table using static mode With Record1 .BeginUpdate Set .DataSource = rs With .Item("ReportsTo") .EditType = DropDownListType Dim i As Long i = 1 .AddItem 0, "- <b>unspecified</b> -" While Not rs.EOF .AddItem rs("EmployeeID").Value, rs("FirstName").Value & " <b>" & rs("LastName").Value & "</b>" i = i + 1 rs.MoveNext Wend rs.MoveFirst End With .EndUpdate End With
The following VC sample binds the "Employees" table in the "NWIND.MDB" database to the component, using an ADODB recordset:
#importrename ( "EOF", "adoEOF" ) using namespace ADODB; BOOL isInstalled(BSTR strProgID, IDispatch** ppObject ) { CLSID clsid = CLSID_NULL; HRESULT hResult = E_POINTER; if (SUCCEEDED( hResult = CLSIDFromProgID( strProgID, &clsid ) )) { IDispatch* pObject = NULL; if ( SUCCEEDED( hResult = CoCreateInstance( clsid, NULL, CLSCTX_ALL, IID_IDispatch, reinterpret_cast (&pObject) ) ) ) { if ( ppObject ) (*ppObject = pObject)->AddRef(); pObject->Release(); return TRUE; } } return FALSE; } COleVariant vtMissing; vtMissing.vt = VT_ERROR; CString strDatabase = "D:\\Program Files\\Microsoft Visual Studio\\VB98\\NWIND.MDB"; CString strError = ""; IDispatch* pObject = NULL; if ( isInstalled( L"ADODB.Recordset", &pObject ) ) { _RecordsetPtr spRecordSet; if ( spRecordSet = pObject ) { CString strConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source= "); strConnection += strDatabase; try { if ( SUCCEEDED( spRecordSet->Open( v("Employees"), v(strConnection), adOpenStatic, adLockOptimistic, 0 ) ) ) { CEditor editor; m_record.BeginUpdate(); m_record.SetLabelSize(96); m_record.SetHBorderField( 6 ); m_record.SetDataSource( spRecordSet ); editor = m_record.GetItem(v("ReportsTo")); editor.SetEditType( /*DropDownListType*/ 3 ); editor.AddItem(0, "- unspecified -", vtMissing ); while ( !spRecordSet->adoEOF ) { CString strName = V2S( &spRecordSet->Fields->GetItem( v("FirstName") )->Value ); strName += " "; strName += V2S( &spRecordSet->Fields->GetItem( v("LastName") )->Value );; editor.AddItem( spRecordSet->Fields->GetItem( v("EmployeeID") )->Value, strName, vtMissing ); spRecordSet->MoveNext(); } spRecordSet->MoveFirst(); m_record.EndUpdate(); } } catch (...) { strError = "The sample database is missing. The 'SAMPLE.MDB' file is not found, or doesn't contain an 'Employees' table."; }; } pObject->Release(); } else strError = "Microsoft ADODB namepsace, 'MSADO15.DLL' file is not installed. ";