home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 40 / IOPROG_40.ISO / SOFT / NETFrameworkSDK.exe / comsdk.cab / samples.exe / QuickStart / howto / doc / adoplus / overviewcontents.aspx < prev    next >
Encoding:
Text File  |  2000-06-09  |  9.4 KB  |  146 lines

  1. <%@ Register TagPrefix="Code" Namespace="Microsoft.Samples.Utils.CodeShow" %>
  2.  
  3.  
  4. <h4>ADO+ Overview</h4>
  5.  
  6. ADO+ is an evolution of the ADO data access model that directly answers user requirements for developing scalable applications. It was architected for the web with scalability, statelessness, and XML in mind.
  7. <P>
  8. ADO+ has some of the same objects from ADO (like Connection and Command), and introduces new objects: DataSets, DataReaders and DatasetCommands.
  9. <p>
  10. One of the new concepts is the XML based DataSet. This object provides a consistent programming model around flat, relational and hierarchical data. It does this by having no knowledge of the source of its data and by representing the data that it holds as collections and data types.  No matter what the source of the data within the dataset is, it is manipulated through the same set of standard APIs exposed though the DataSet and its subordinate objects.
  11. <P>While the DataSet has no knowledge of the source of its data, the managed provider has detailed and specific information.  The role of the managed provider is to connect, fill, and persist the DataSet to and from data stores. The ADO and SQL Server managed providers that are part of the NGWS frameworks provide three basic objects: Commands, Connections and DataSetCommands. 
  12. In the remaining sections of this document, weÆll walk through each of the parts of the DataSet and the ADO/SQL Managed providers explaining what they are, and how to program against them.
  13. <p>
  14. The important distinction between this evolved stage of ADO+ and previous data architectures is that there exists an object--the DataSet--that is separate and distinct from any data stores.  Because of that, we can use the dataset as standalone entity. You can think of the Dataset as an always disconnected recordset that knows nothing about where the data came from, or where it is going.
  15. Inside a DataSet, much like a database, there are tables/columns, relationships, constraints, views etc.  
  16. A DataSetCommand is the object that connects to the database to fill the DataSet. Later it connects to the database to update the data.  
  17. Getting the Data
  18. In the past, data processing has been primarily connection based. Now, in an effort to make multi-tiered apps more efficient, data processing is turning to a message based approach that revolves around chunks of information. At the center of this approach is the DatasetCommand, which provides a bridge to retrieve and save data between a Dataset and its source data store. It accomplishes this by requests to the appropriate SQL commands against the data store. 
  19. <p>
  20. The following sections will introduce you to some objects that have evolved, and some that are new. These objects are:
  21. <ul>
  22. <li><b>Connections</b>.
  23. For connection to and managing transactions against a database.
  24. <li><b>Commands</b>.
  25. For issuing SQL Commands against a database
  26. <li><b>DataReaders</b>.  For reading data readonly off a stream
  27. <li><b>Datasets and DatasetCommands</b>.  For pushing data into a dataset, and reconciling data against a database. For storing, remoting and programming against flat data, xml data and relational data
  28. </ul>
  29.  
  30. Note: When dealing with connections to databases there are two different options: ADO and SQL. In these samples we will use the SQL libraries. These are written to talk directly to MS-SQL server. The ADO libraries are used to talk to any OLEDB provider (as it uses OLEDB underneath).
  31. <p>
  32.  
  33. <a name="subhead2">
  34. <span class="subhead">Connections</span>
  35. <p>
  36. Connections are used to talk to databases. Commands travel over connections and result sets are returned in the form of streams which can be read by DataReaders, or pushed into DataSet objects.
  37. <p>
  38.  
  39. The example below shows how to create a connection.  Connections can be opened explicity by calling the Open method on the connection, or will be opened implicilty when using a DatasetCommand.
  40. <p>
  41.  
  42.     <Acme:SourceRef 
  43.       RunSample="/quickstart/howto/samples/adoplus/cs/adooverview1.aspx" 
  44.       ViewSource="/quickstart/howto/samples/adoplus/cs/adooverview1.src"
  45.       Icon="/quickstart/images/genicon.gif"
  46.       Caption="AdoOverview1.aspx"
  47.       runat="server" />
  48.     </a>   
  49.  
  50. <p>
  51. <a name="subhead2">
  52. <span class="subhead">Commands</span>
  53. <p>
  54. Commands contain the information that is submitted to a database. A command can be a stored procedure call, an update statement, or a statement that returns results. You can also use input and output parameters and return values. The example below shows how to issue an insert statement against the Northwind database.<p>
  55.  
  56.  
  57. <p>
  58.  
  59. <Acme:SourceRef 
  60.   RunSample="/quickstart/howto/samples/adoplus/cs/adooverview2.aspx" 
  61.   ViewSource="/quickstart/howto/samples/adoplus/cs/adooverview2.src"
  62.   Icon="/quickstart/images/genicon.gif"
  63.   Caption="AdoOverview2.aspx"
  64.   runat="server" />
  65. </a>
  66.  
  67. <p>
  68.  
  69. <span class="subhead">DataReaders</span>
  70. <p>
  71. DataReaders are somewhat synonymous with a read-only/forward-only cursor over data. The DataReader API supports regular (flat, rectangular data) as well as hierarchical data. You can use a DataReader after executing a command to a database. For example, if you wanted to simply show the results of a search list in a web page, a DataReader is very appropriate.
  72. DataReaders are returned after executing a command. The syntax is different from a recordset.
  73. <p>
  74.  
  75. <Acme:SourceRef 
  76.   RunSample="/quickstart/howto/samples/adoplus/cs/adooverview3.aspx" 
  77.   ViewSource="/quickstart/howto/samples/adoplus/cs/adooverview3.src"
  78.   Icon="/quickstart/images/genicon.gif"
  79.   Caption="AdoOverview3.aspx"
  80.   runat="server" />
  81. </a>
  82.  
  83. <p>
  84.  
  85. <span class="subhead">DataSets and DatasetCommands</span>
  86. <p>
  87. <B>DataSets</B><BR>
  88. At the higest level, you can think of a DataSet as an always disconnected Recordset on steroids. The DataSet object represents a cache of data, with database like behaviours. There exists tables, columns, relationships, contraints, and data.
  89.  However, though a DataSet can and does behave much like a database, it is important to know that DataSet objects do not talk to databases. This important distinction allows the developer to anticipate an always consistent programming model regardless of where the data came. 
  90. Data coming from a database, an XML file, from code, or user input can all be put into DataSet objects and converted into files, forms, or databases. As changes are made to the DataSet, they are tracked; much like tracking changes in a document. The DataSet can provide a message (GetChanges()) in the form of another DataSet that can be used by DatasetCommands (or other objects) to update sources of data like databases.
  91. <P>
  92. DataSets have many XML characteristics, including the ability to produce and consume XML Data and XML Schemas. XML Schemas can be used to describe schemas interchanged via WebServices.  In fact, Datasets with schemas can be compiled for type safety and statement completion.
  93.  
  94. <P>
  95. <B>DataSetCommands (ADO/SQL)</B><BR>
  96. DataSets can move in and out of sources using an object with the IDataSetCommand interface. We provide both the ADODatasetCommand and the SQLDatasetCommand that implements this interface.
  97. A DataSetCommand is much like a Command on steroids. While a command has one CommandText property, a CommandSet has four--to represent InsertCommand, SelectCommand, UpdateCommand and DeleteCommand. The DatasetCommand can generate these at run-time based upon a select statement.  Additionally, a developer can specify them in code, for example, when using stored procedures.
  98.  
  99.  
  100. <P>
  101. <div class="code">
  102.  
  103. <br>    SQLConnection MyConnection = new SQLConnection("server=localhost;uid=sa;pwd=;database=northwind");
  104. <br>    SQLDataSetCommmand MyDataSetCommand = new SQLDataSetCommand("select * from customers", MyConnection);
  105. <BR>
  106. <br>    MyDataSetCommand.InsertCommand = "sp_InsertCustomer"
  107. <br>    MyDataSetCommand.InsertCommand.CommandType = CommandType.StoredProcedure;
  108. <br>    MyDataSetCommand.DeleteCommand = "sp_DeleteCustomer"
  109. <br>    MyDataSetCommand.DeleteCommand.CommandType = CommandType.StoredProcedure;
  110. <BR>    MyDataSetCommand.UpdateCOmmand = "sp_UpdateCustomers"
  111. <br>    MyDataSetCommand.UpdateCommand.CommandType = CommandType.StoredProcedure;
  112. </div>
  113.  
  114. <P>
  115.  
  116.  
  117. When the DatasetCommand is given the diffs:<P>
  118.  
  119. <br>
  120. <div class="code">
  121.     MyDatasetCommand.Update(MyDataSet)<P>
  122. </div>
  123. The records are appropriately mapped to the given commands accordingly.
  124. <p>
  125. The sample below illustrates loading a DataSetCommand via a select statement.  Then it updates, deletes and adds some records within the DataSet. Finally it sends those updates to the database via the DatasetCommand. 
  126.  The constructed DeleteCommand, InsertCommand and UpdateCOmmand are shown in the page. It also illustrates using multiple DataSetCommands to load multiple tables into the DataSet (Customers and Orders).
  127. <BR><img src="/quickstart/howto/images/AdoDataSet.gif">
  128. <Acme:SourceRef 
  129.   RunSample="/quickstart/howto/samples/adoplus/cs/adooverview4.aspx" 
  130.   ViewSource="/quickstart/howto/samples/adoplus/cs/adooverview4.src"
  131.   Icon="/quickstart/images/genicon.gif"
  132.   Caption="AdoOverview4.aspx"
  133.   runat="server" />
  134. </a>
  135.  
  136. <p>
  137.  
  138. <h4>Section Summary</h4>
  139. <ol>
  140. <li>ADO+ is the next evolution of ADO for the NGWS Framework.
  141. <li>ADO+ was created with n-Tier, statelessness and XML in the forefront.  Two new objects, DataSets and DataSetCommands are provided for these scenarios.
  142. <li>ADO+ can be used to get data from a stream, or to store in a cache for updates.
  143. <li>There is a lot more information about ADO+ in the documentation. 
  144. </ol>
  145.  
  146. <p>