Faculty of Electronic Engineering 1 Database Access API’s Aleksandar Stanimirović Leonid Stoimenov Aleksandar Milosavljević
Faculty of Electronic Engineering 2 Exercise goals Get familiar with connecting to different data sources through ADO Get know the basic of ADO object model Get familiar with using VB as rapid application development tool Get familiar with using ADO in VB
Faculty of Electronic Engineering 3 ADO Stands for ActiveX Data Objects Part of Universal Data Access architecture ADO object hierarchy Programming with ADO
Faculty of Electronic Engineering 4 Visual Basic integrated environment Object viewer Codingwindow Formdesigner Toolbox Propertywindow
Faculty of Electronic Engineering 5 ADO support in VB Programming with automated data binding tools Programming with ADO objects in VB code
Faculty of Electronic Engineering 6 Adding ADO support in VB ADO support added by default User must add ADO support
Faculty of Electronic Engineering 7 Programming with automated data binding tools Data aware controls ADO Data Control Data Environment Designer
Faculty of Electronic Engineering 8 Data aware controls Almost all VB controls are data aware: Four properties for binding with data source: 1.Data source 2.Data member 3.Data field 4.Data format
Faculty of Electronic Engineering 9 ADO Data Control
Faculty of Electronic Engineering 10 Data Environment Designer
Faculty of Electronic Engineering 11 Programming with ADO objects in VB Set cnNWind = New ADODB.Connection Set rsEmployees = New ADODB.Recordset Dim sConnect As String sConnect = “Provider=Microsoft.Jet.OLEDB.4.0;Data Source= NWind.mdb” cnNWind.Open sConnect rsEmployees.Open “Select * From Employees Order By LastName,FirstName”, cnNWind Do While Nor rsEmployees.EOF Debug.Print rsEmployees!FirstName + rsEmployees!LastName LooprsEmployees.ClosecnNWind.Close
Faculty of Electronic Engineering 12 Exercise 1. Create Data project in VB 2. Using existing form in project show data from specified table in database Place ADO Data control on form Link ADO Data control with existing exercise database on Oracle or MS SQL Server Place controls on form and link them with ADO Data control Add new form in project and show data based on previous exercise query. Using Data environment create connection to existing database on Oracle or SQL Server Create Command object that executes specified SQL query. Place on database fields from Data environment. Add code that scroll database data.