Archive for the ‘theory’ Category

objects and web scripting

scripting typically involves creating objects in order to execute certain tasks to achieve a desired outcome. and so … how do i create an object? it sounds silly, really. but, honest … its abstract … a tough concept around which to wrap one’s head. its the core of modern-day programming, though. so i had better start getting it.

object creation involves 2 steps.

(1). create an object definition ~ the code containing methods and properties of the object. methods ~ directions for making the object. properties ~ characteristics that typify the object.

create a constructor function ~ a named group of 1 or more programming statements that can create new objects. note – by convention, capitalize the first letter of a constructor function.

add properties ~ identified by object name “dot” property name. refer to the newly created, not yet instantiated objects as “this”

objectName.propertyName = value

add methods ~ (methods = functions called from within the method.) name the method, assign a function. use action words when naming methods.  identified using the syntax below. (argument = input to subroutine … used to assign a value to a property of the new object)

objectName.methodName(arguement)

(2) instantiation ~ create an  instance of the newly defined object. specify a unique name for the new object. assign the object to the recently created object definition using the “new” keyword.

steps in object instantion ~ variable assigned a value ~ variable value passed as a parameter (parameters act as local copies of the argument) to the new object ~ parameter used to assign variable value to an object property ~ object property used by the object’s show method ~ show calls the object’s display method, which writs to the browser.

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.