180 likes | 457 Views
ADO.NET Classes. What is ADO.NET Identifying All ADO.NET Objects Using ADO.NET in Windows App. Introduction. Set of Classes to Hold/Retrieve Data Two sets of classes - Connect to Databases - In-Memory Datasets (holds data). Identify Classes of ADO.NET. Connection Command
E N D
ADO.NET Classes What is ADO.NET Identifying All ADO.NET Objects Using ADO.NET in Windows App Prepared By Hafeez Mohammed
Introduction • Set of Classes to Hold/Retrieve Data • Two sets of classes • - Connect to Databases • - In-Memory Datasets (holds data) Prepared By Hafeez Mohammed
Identify Classes of ADO.NET • Connection • Command • DataAdapter (intermediate layers) • DataReader • DataSet • DataTable • -DataRow, DataColumn • DataView Prepared By Hafeez Mohammed
DataSource not limited to DB • DataSource typically is a Database engine • Can be a spectrum of popular DB’s • MSSQL Server7.0/2000 • Oracle8/8i/9i • MSAccess97/2000 • Or even text files or Spreadsheets • Can be XML files as well Prepared By Hafeez Mohammed
Connection Object • Connection is used to open connection with a database • Two default types of this class • - OleDb datasource • - Sql Server datasources Prepared By Hafeez Mohammed
Command Object • Used to submit SQL statements to the backend datasource • Can pass regular sql statements like Select, Insert or delete • Or can pass the name of the stored procedures • Sometimes CommandBuilder Object is used to build the Command Object Prepared By Hafeez Mohammed
DataAdapter Object • Used to populate a DataSet or a DataTable in memory • Does everything automatically like creating Connection Object and connecting to the DB, uses the SQL with Command Object to retreive the data and fills up a DataSet or DataTable Class • Disconnects from the DB Prepared By Hafeez Mohammed
DataReader Object • If you quickly want to fill a ListBox, Combo or a Grid use a DataReader Object • It’s a forward/read only cursor • It cannot be used to build a DataSet or a DataTable Prepared By Hafeez Mohammed
DataSets/DataViews • Also called in-memory classes • Holds the Original and modified data • Does not know how to communicate with the datasources • Has DataRows and DataColumns • Specific view of Data • Can set filters, sorting here Prepared By Hafeez Mohammed
SQL Client and OLE DB • There are two different flavors of the Connection, Command, CommandBuilder, DataAdapter and DataReader classes. • One set of these classes, prefixed with “OleDb” and use the OLE DB providers to get at a data source. The other set are prefixed with “Sql” and use native providers to talk directly to SQL Server. These two sets of classes come from two separate namespaces. Prepared By Hafeez Mohammed
Types of ADO.NET Classes • OLEDB or SQLClient • OleDB provides you data from any datasource where as SQLClient is made purely for SQL Server • OleDB uses all classes prefixed with OleDB • OleDB.OleDBConnection • OleDB.OleDBDataAdapter Prepared By Hafeez Mohammed
Native Client • SQLClient uses SQLClient prefix • SQLClient.SQLConnection • SQLClient.SQLDataAdapter • Will get better performance • Other Native Client classes are coming soon for clients like Oracle, MSAccess etc…. Prepared By Hafeez Mohammed
Test Your Data Access Knowledge • 1.Which namespace would you use to go after an Oracle database? • 2.Which namespace would you use to go directly at SQL Server? • 3.Which class retrieves data from the data source? • 4.Which class will build a new command object for you? • True or False: A DataSet can update data directly in an SQL Server database? Prepared By Hafeez Mohammed