120 likes | 283 Views
Database Access API’s. Aleksandar Stanimirovi ć Leonid Stoimenov Aleksandar Milosavljevi ć. 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
E N D
Database Access API’s Aleksandar Stanimirović Leonid Stoimenov Aleksandar Milosavljević Faculty of Electronic Engineering
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
ADO • Stands for ActiveX Data Objects • Part of Universal Data Access architecture • ADO object hierarchy • Programming with ADO Faculty of Electronic Engineering
Visual Basic integrated environment Object viewer Toolbox Coding window Property window Form designer Faculty of Electronic Engineering
ADO support in VB • Programming with automated data binding tools • Programming with ADO objects in VB code Faculty of Electronic Engineering
User must add ADO support ADO support added by default Adding ADO support in VB Faculty of Electronic Engineering
Programming with automated data binding tools • Data aware controls • ADO Data Control • Data Environment Designer Faculty of Electronic Engineering
Data aware controls • Almost all VB controls are data aware: • Four properties for binding with data source: • Data source • Data member • Data field • Data format Faculty of Electronic Engineering
ADO Data Control Faculty of Electronic Engineering
Data Environment Designer Faculty of Electronic Engineering
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 Loop rsEmployees.Close cnNWind.Close Faculty of Electronic Engineering
Exercise • Create Data project in VB • 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. Faculty of Electronic Engineering