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.
No comments yet
Leave a reply








