Archive for the ‘data access’ Category
ADO.NET ~ classes and objects
ADO.NET ~ the name for a set of classes used with C# and the .NET framework to access data in a relational, table-oriented format. this includes relational databases such as Acess, SQL as well as other databases and even non-relational data sources. located within the System.Data.dll assembly. developed for the purpose of providing a set of easy-to-use classes with which to access data … extensibility: supports more data sources that predecessors … support for multi-tiered internet applications.
classes and objects detailed in a previous post.
DataReader ~ five steps to retrieving data from a dataTable in SQL~ 1.connect to the data source … 2. open the connection … 3. issue an SQL query … 4. read and display the data with the data reader … 5. close the data reader and connection.
DataSet ~ 1. create connection … 2. create a dataAdapter object … 3. create a dataSet … 4. fill dataSet with data … 5. use a foreach statement to write data from the dataSet to the console … no need to open or close connection – data adapter manages that.
*data updated through the dataSet object and its objects, i.e. dataRow.
SqlDataAdpater.Update () ~ this method goes thru the rows in a DataTable to check for data marked for changes. each DataRow object in the Rows collection has a property, RowState, tracking whether the current row marked for deletion, addition, modification, or whether unchanged. any changes made get reflected in the database.
Find () ~ a method in the DataTable Rows collection that ~ goes through rows in a DataTable finds data in rows by using the PK.
Delete () ~ a method in the DataRow object that deletes the current row.
*use Remove () to remove rows from dataSet, while leaving underlying database unchanged.
**reproduce graphics p. 619 … p. 634 … **
DataRelation Object ~ used to describe the relation betweeen multiple DataTable objects. Each DataSet has a Relations collection of DataRelations that enables you to find and manipulate related tables. ~objects to represent relationships between fields, data~ creating objects that represent relationships enable navigation among the data of related tables.
Add () method of Relations accepts a string name for the relationship and two DataColumns: the parent column, followed by the child column.
GetChildRows () method resides in DataRow object ~ loops thru each DataRow in the Rows collection and returns just the related rows. (GetParentRows() works analogously)
to access data with multiple relations, initialize a connection to the data source, create a DataSet and then a data adapter for each table required …. then build a data relations object for each of the relationships between the tables … then use foreach loops to process data using child-parent hierarchy.
DataSet has several methods that process XML ~ WriteXML() … ReadXML()
DataAdapter also has properties to access SQL commands used in data update more directly than with command builder.
Stored Procedures require passage to the comman objects constructor of the stored procedure’s name and the connection used. items to remember:
1. set the CommandType of the command object to StoredProcedure
2. with parameters collection its possible to create and add input, output and return parameters for use with stored procedures
3. stored procedure also make it possible to retrieve information about the DataTable, DataRow, and DataColumns using the Get and Set methods
4. it’s possible to derive parameters from the parameters collection using the CommandBuilder’s DeriveParameters method.
linking application to data
so … we have an application, written in c#. we have a rockin’ sql database. how do we get it together? how do we get sql and c# to talk to each other? that’s what this post will discuss. we need an API – an application programming interface – that will facilitate our program’s access to the data to carry out specified functions. a number of alternatives exist.
1. ODBC ~ open database connectivity ~ a procedural API (common set of functions/methods) for using SQL queries to access data. limitations: unsuitable for accessing non-relational data such as spreadsheets, text files and xml files. An implementation of ODBC will contain one or more applications, a core ODBC library, and one or more “database drivers”. The core library, independent of the applications and DBMS, acts as an “interpreter” between the applications and the database drivers, whereas the database drivers contain the DBMS-specific details. Thus a programmer can write applications that use standard types and features without concern for the specifics of each DBMS that the applications may encounter. Likewise, database driver implementors need only know how to attach to the core library. This makes ODBC modular.
2. OLE DB ~ object linking and embedding, database ~ a procedural API developed by MS as a successor to ODBC, to extend its feature set to support a wide variety of non-relational databases, such as object databases, and spreadsheets. OLE DB separates the data store from the application that needs access to it through a set of abstractions that include the datasource, session, command and rowsets. This was done because different applications need access to different types and sources of data and do not necessarily want to know how to access functionality with technology-specific methods. OLE DB is conceptually divided into consumers and providers. The consumers are the applications that need access to the data, and the provider is the software component that implements the interface and therefore provides the data to the consumer.
3. ADO.NET ~ activeX data object .NET ~ an API that’s a base class in the MS .NET framework. ADO.NET consists of a set of objects in the Systems.Data namespace that communicate with the database via .NET providers. these objects allow connectivity to the database to retrieve, edit, delete and insert data in the database and manipulate the data within the program. ADO.NET consists of two parts – (i). the DataSet and (ii). the .NET provider.
(i). DataSet ~ does not provide or maintain connectivity to the database. provides a copy of the data source – in memory – with which to work. consists of a nested collection of objects that allow for manipulation of data within the dataset. see figure below.
(ii).NET data provider objects ~ consists of objects that faciliate connectivity to individual data sources. each provider resides in its own namespace within the System.Data namespace. @ present, 4 main components. see figure below.
to access an SQL Server database requires an OLE DB connection provider.
Leave a Comment
Leave a Comment









