10
Programming with Programming with ADO.NET ADO.NET By By Sam Nasr Sam Nasr April 27, 2004 April 27, 2004

Programming with ADO.NET By Sam Nasr April 27, 2004 Programming with ADO.NET By Sam Nasr April 27, 2004

Embed Size (px)

Citation preview

Page 1: Programming with ADO.NET By Sam Nasr April 27, 2004 Programming with ADO.NET By Sam Nasr April 27, 2004

Programming with ADO.NETProgramming with ADO.NET

ByBySam NasrSam Nasr

April 27, 2004April 27, 2004

Page 2: Programming with ADO.NET By Sam Nasr April 27, 2004 Programming with ADO.NET By Sam Nasr April 27, 2004

What is ADO.Net?What is ADO.Net?

ADO.NET = ActiveX Data ObjectsADO.NET = ActiveX Data Objects

A set of libraries included within the .NET A set of libraries included within the .NET FrameworkFramework

ADO.NET objects are contained in the ADO.NET objects are contained in the System.DataSystem.Data namespace. namespace.

Page 3: Programming with ADO.NET By Sam Nasr April 27, 2004 Programming with ADO.NET By Sam Nasr April 27, 2004

ADO.Net TerminologyADO.Net Terminology

Data Store: an object containing data.Data Store: an object containing data.

Data Provider: Classes designed to Data Provider: Classes designed to communicate with a data store.communicate with a data store.

Page 4: Programming with ADO.NET By Sam Nasr April 27, 2004 Programming with ADO.NET By Sam Nasr April 27, 2004

Advantages of ADO.NETAdvantages of ADO.NET

Built for CLR environment to maximize performance.Built for CLR environment to maximize performance.

Greater Extensibility: results can be retrieved in XML.Greater Extensibility: results can be retrieved in XML.

Allows the use of the Disconnected Objects (DataSet)Allows the use of the Disconnected Objects (DataSet)

Allows multiple dataset objects for a join query.Allows multiple dataset objects for a join query.

Allows update logic when using a Disconnected Object.Allows update logic when using a Disconnected Object.

Page 5: Programming with ADO.NET By Sam Nasr April 27, 2004 Programming with ADO.NET By Sam Nasr April 27, 2004

All ADO.NET objects can be separated into 2 categories::

1. Connected: Objects that communicate 1. Connected: Objects that communicate directly with the database.directly with the database.

2. Disconnected: Objects that allow the user 2. Disconnected: Objects that allow the user to work with the data offline.to work with the data offline.

Page 6: Programming with ADO.NET By Sam Nasr April 27, 2004 Programming with ADO.NET By Sam Nasr April 27, 2004

Connected ObjectsConnected Objects

ConnectionConnection

TransactionTransaction

DataAdapterDataAdapter

CommandCommand

ParameterParameter

DataReaderDataReader

Page 7: Programming with ADO.NET By Sam Nasr April 27, 2004 Programming with ADO.NET By Sam Nasr April 27, 2004

Disconnected ObjectsDisconnected Objects

DataSetDataSet

DataTableDataTable

DataViewDataView

DataRowDataRow

DataColumnDataColumn

ConstraintConstraint

DataRelationDataRelation

Page 8: Programming with ADO.NET By Sam Nasr April 27, 2004 Programming with ADO.NET By Sam Nasr April 27, 2004

Syntax for a single query Syntax for a single query statementstatement

SqlCommand cmd = newSqlCommand cmd = new

Sqlcommand(“select * from customers”, _ Sqlcommand(“select * from customers”, _ conn)conn)

Adapter.fill(ds) ‘Adapter.fill(ds) ‘to fill a single datasetto fill a single dataset

Adapter.fill(ds, “customers”) Adapter.fill(ds, “customers”) ‘to fill a single ‘to fill a single dataset and name it.dataset and name it.

Page 9: Programming with ADO.NET By Sam Nasr April 27, 2004 Programming with ADO.NET By Sam Nasr April 27, 2004

Syntax for a multiple query Syntax for a multiple query statementstatement

SqlCommand cmd = new _ SqlCommand cmd = new _

Sqlcommand(“select * from customers; Sqlcommand(“select * from customers; select * from orders;”, conn)select * from orders;”, conn)

Adapter.fill(ds)Adapter.fill(ds)

Ds.tables[0].TableName = “Customers”Ds.tables[0].TableName = “Customers”

Ds.tables[1].TableName = “Orders”Ds.tables[1].TableName = “Orders”

Page 10: Programming with ADO.NET By Sam Nasr April 27, 2004 Programming with ADO.NET By Sam Nasr April 27, 2004

Using .UDL filesUsing .UDL files

.UDL = Universal Data Link.UDL = Universal Data Link

UDL files store a connection string for any UDL files store a connection string for any data connectivity task.data connectivity task.

Interface is identical to the Data Adapter.Interface is identical to the Data Adapter.