Archive for the ‘classes’ 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.

classes and encapsulation

Encapsulation refers to the design concept that each object carries its own data and provides a set of services that are involved in calling the objects methods. objects provide services by sending and receiving messages from other objects. encapsulation means users can access an object’s services and functionality, without having ready access to the object’s underlying data itself. encapsulation facilitates software design and development using a ‘block method’ as well as object reuse, information hiding, and control over each object’s ability to view other objects.

classes facilitate the encapsulation process, by defining object program logic and data fields. essentially, classes definitions describe the structure of executing objects ~ that is, they act as templates for the creation of new instances (known in the jargon as ‘instantiation’ ) of the class object. methods that exist at the object level, as opposed to the instance level, can access the data of all object instances in the class. methods that exist at the level of an object’s instance can only access that particular data. the goal of object-oriented programing becomes achieving a balance between the degree of linkages among the various classes of any program and the degree of consistency within each individual class.