[ Pobierz całość w formacie PDF ]
.NoteThe term firehose refers to the fact that data gushes out of aforward-only, read-only cursor.The SqlDataAdapter and DataSet objects com bine to enable both data access anddata m anipulation capabilities.This is im portant because SqlDataReader obj ectsprovide strictly data access capabilities (that is, you cannot perform update, insert, or delete tasks with a SqlDataReader obj ect).Use the SqlDataAdapter Fillm ethod to populate a DataSet object with values from a SQL Server data source.Because a single DataSet obj ect can work with m ultiple SqlDataAdapter and OLEDB DataAdapter objects, you can populate a single DataSet object withheterogeneous data sources from m ultiple database servers.For exam ple, youcan populate a single data set with tables, views, or stored procedures from twodifferent SQL Server instances or from Access and Oracle data sources in additionto a SQL Server data source.Furtherm ore, you can j oin all the data sourceswithin a DataSet object on fields with com m on data types.Use the SqlDataAdapter Update m ethod to transfer changes from a DataSetobject to its underlying data sources.When users perform insert, update, anddelete operations against the contents of a DataSet object, those m odificationsdon t transfer to the data sources for the DataSet object until your applicationinvokes the Update m ethod for a SqlDataAdapter object underlying the datasource.Despite its nam e, the Update m ethod can process all three types of datam anipulation operations.However, you need a custom SqlCom m and object toaccom m odate each type of data m anipulation task.Therefore, a SqlDataAdaptercan relate to a rem ote data source through m ore than a single SqlCom m andobject.Between the tim e you populate the DataSet object and the tim e yourapplication invokes the SqlDataAdapter Update m ethod, it s possible for theunderlying data source on a SQL Server instance to change.Any changes cancause exceptions because the original values in a data set can be different fromthe current values in the SQL Server data source.The SqlDataAdapter has eventsand properties to help m anage exceptions that can occur during an updateprocess.Figure 1-4 presents a schem atic diagram sum m arizing howSqlDataAdapter and DataSet obj ects exchange data with an underlying datasource.By contrasting this diagram with the one in Figure 1-3, you can easilyspot an im portant difference between the SqlDataReader and a DataSet objectsupplied by a SqlDataAdapter object.The capability of perform ing datam anipulation with the DataSet object is a critical feature that m eans m anyapplications will rely on a DataSet obj ect instead of a SqlDataReader obj ect.Figure 1 - 4.A schem atic illustrating the route by w hich SqlDataAdapterand DataSet objects exchange values w ith a SQL Server data source. The DataSet object offers an object m odel for m anaging the individual elem entswithin it.The DataSet object consists of a DataTable collection (along with otherelem ents).This collection can contain one or m ore tables.You can create thesetables with the SqlDataAdapter Fill m ethod when you initially populate a DataSetobject from a SQL Server data source.The SelectCom m and property, which is aT-SQL statem ent or a stored procedure, for a SqlDataAdapter obj ect can serve asthe basis of a table in the DataTable collection for a DataSet object.You can usem ultiple SqlDataAdapter obj ects to add m ore than one table to a DataSet obj ect.Each table has a rich object m odel that perm its the designation of prim ary keysand foreign keys as well as constraints to m anage data integrity within a table.One very practical use for the DataTable collection and the object m odel forindividual tables is that you will use it to navigate am ong the values within aDataSet object.NoteIn addition to referencing the column values of rows withinan individual DataTable in a DataSet object, you canreference the schem a of DataTable objects within a DataSetobject.This is particularly convenient when you want tocreate a table that you want to populate with data from anXML docum ent.The DataSet object supports four key m ethods for exchanging its data with XMLdocum ents.Two of the m ethods are used for writing XML docum ents based on aDataSet object, and two are for reading XML docum ents into a DataSet object.Within each pair, one m ethod focuses just on transferring schem a inform ationand the other focuses on transferring data as well as schem a inform ation.A Starter ADO.NET Sam pleThis section presents a starter sam ple to illustrate som e of the conceptsdescribed in the preceding section.Don t worry about following the details of theexam ple.I nstead, pay attention to how easy it is to get started with ADO.NET.This section reinforces the presentation of basic ADO [ Pobierz całość w formacie PDF ]

  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • hanula1950.keep.pl