Presentation is loading. Please wait.

Presentation is loading. Please wait.

Intro to ADO.NET1 CTEC2902 Advanced Programming Introduction to ActiveX Data Objects.NET (.NET Class Library for Database Processing)

Similar presentations


Presentation on theme: "Intro to ADO.NET1 CTEC2902 Advanced Programming Introduction to ActiveX Data Objects.NET (.NET Class Library for Database Processing)"— Presentation transcript:

1 Intro to ADO.NET1 CTEC2902 Advanced Programming Introduction to ActiveX Data Objects.NET (.NET Class Library for Database Processing)

2 Intro to ADO.NET2 The story so far… You know how to Use existing classes (essential when using ADO.NET) Structure data in a RDB Use SQL to process relational data You are now ready to start developing DB applications Let’s carry on… Getting Started

3 Intro to ADO.NET3 RDB ComponentADO.NET class DatabaseDataSet (for future use) TableDataTable RecordDataRow FieldItem RDB Classes in ADO.NET Introduction to ADO.NET All underpinned by SQL The focus of our module

4 Intro to ADO.NET4 DBMS (Source) ADO.NET Programming Components Application Written in ASP + VB.NET Data Table SQL-populated data tables in VB + ADO.NET SQL Server or Access or MySQL or Oracle ConnectorData Adapter No need to get involved; Instead, use custom-made class, named … clsSQLServer Introduction to ADO.NET Make sure you have a copy of its API

5 Intro to ADO.NET5 Programming Steps 1.Create a database object, using clsSQLServer (to link to & process a database, via SQL in stored procedures ) 2.Create a data table object, using DataTable class (to save the data returned by SELECT) 3.Use the QueryResults property of your database object to populate your data table object, for viewing and generating reports Introduction to ADO.NET

6 Intro to ADO.NET6 Introduction to ADO.NET Step 1 – Creating Database objects Dim object As New clsSQLServer(DBName) Your local object Class name Name of database to open E.g. Dim MyDB As New clsSQLServer(“BSC_Computing.mdf”) Dim AnotherDB As New clsSQLServer(txtDBName.Text)

7 Intro to ADO.NET7 Step 2 – Creating Data Table Objects Dim datatable_object As New DataTable e.g. to create data table objects Dim dtStudents As New DataTable Dim dtModules As New DataTable Note the prefix “dt” for data table objects When data tables are created, they are empty; so we must populate them Introduction to ADO.NET To hold the records returned by SELECT

8 Intro to ADO.NET8 Step 3 - Populating Data Tables Introduction to ADO.NET Dim DB As New clsSQLServer(“MyDB.mdf") Dim dtStaff As New DataTable DB.Execute("sp_tblStaff_GetName") dtStaff = DB.QueryResults Name of stored procedure Results from SELECT after execution Your table

9 Intro to ADO.NET9 Introduction to ADO.NET Sample Stored Procedure CREATE PROCEDURE dbo.sp_tblStaff_GetAll AS SELECT * FROM tblStaff

10 Intro to ADO.NET10 Introduction to ADO.NET CREATE PROCEDURE dbo.[sp_tblStaff_GetName] AS SELECT Surname + ', ' + FirstName AS Fullname FROM tblStaff Another Sample Stored Procedure

11 Intro to ADO.NET11 Structure of a Data Table Records Rows Tuples 0 1 2 3 etc Fields, Columns, Attributes 0 1 2 3 etc. Data item Cell value A data table can be viewed as a zero-based, 2-D array Can also be referred to by field name Introduction to ADO.NET

12 Intro to ADO.NET12 A Data table may contain (depending on the SELECT command): 1.All the records from an RDB table e.g. all students on a given module 2.Some of the records from an RDB table; called “subset” e.g. students who have not yet sat the phase test 3.Records from 2 or more RDB tables; called “superset” e.g. students + their course & mentors

13 Intro to ADO.NET13 How do you view data table contents? Use Data-Bound List Boxes (see example) Use Data-Grid (see example)


Download ppt "Intro to ADO.NET1 CTEC2902 Advanced Programming Introduction to ActiveX Data Objects.NET (.NET Class Library for Database Processing)"

Similar presentations


Ads by Google