RSS


[ Pobierz całość w formacie PDF ]
.When you are working with XML data, an XML menu becomes available.Thismenu allows you to generate schema and validate data against the schema.When you create schemas from existing documents, all data types are declaredas strings.You can alter this manually in the XML Designer.Creating Schemas from DatabasesYou can also create an XSD schema from the structure of existing data.To dothis, you add a new schema item to your project and drag on the chosen tablesor views from the hierarchy displayed in the Data Connections of ServerExplorer.Again, the data types will need editing. Module 8: Using ADO.NET 51Working with SchemasYou can view schemas in Visual Studio.NET either as XML or in the DesignerWindow, which is a user-friendly display of the schema.In this window, youcan edit existing schemas (adding, removing, or modifying elements andattributes) and create new schemas.The following illustration shows the Designer Window:Validating XML Documents Against SchemaYou can use the XML Designer to validate data against XML schema.If youhave an existing document that you are adding data to, you can use thistechnique to validate that the new data conforms to the structure described inthe schema.Use the following steps to validate an XML document against an XML schema.1.Load the XML document into the XML Designer.2.On the XML menu, click Validate XML Data.Any validation errors will be noted in the Task List. 52 Module 8: Using ADO.NETUsing XML Data and Schemas in ADO.NETTopic ObjectiveTo discuss how to load XMLdata into an ADO.NETDataSet.Loading XML Data into a DataSetLead-inDimDim datXML As DataSet = New DataSet()datXML As DataSet = New DataSet()Accessing XML data bydatXML.ReadXml("c:\publishers.xml")datXML.ReadXml("c:\publishers.xml")MessageBox.Show(datXML.Tables(0).Rows(0)(0).ToString)means of ADO.NET solvesMessageBox.Show(datXML.Tables(0).Rows(0)(0).ToString)an issue that developershave had in the past.Using a Typed DataSetIncreases performanceSimplifies codingMessageBox.Show(pubs.Publishers(0).pub_id)MessageBox.Show(pubs.Publishers(0).pub_id)One of the issues experienced by developers in the past has been trying tomanipulate XML data within their applications.In earlier data accesstechnologies, there was no ability to do this.In ADO.NET, you can populate aDataSet from an XML document.This allows you to access the data in asimple fashion.Loading XML Data into a DataSetYou can load an existing XML document into a DataSet by using theReadXML method of the DataSet.This requires one argument of the fullyqualified path and file name of the XML document to be loaded.The following example shows how to load the data and display the first columnin the first row:Dim datXML As DataSet = New DataSet( )datXML.ReadXml("c:\publishers.xml")Dim drFirstRow As DataRow = datXML.Tables(0).Rows(0)MessageBox.Show(drFirstRow(0).ToString) Module 8: Using ADO.NET 53Using Typed DataSetsDataSets can be typed or untyped.A typed DataSet is simply a DataSet thatuses information in a schema to generate a derived DataSet class containingobjects and properties based on the structure of the data.You can create a typed DataSet by using the Generate DataSet commandfrom the schema view.You can add a DataSet object to a form, and link it tothe typed dataset already in the project, and then work with the DataSet in theusual way.In untyped DataSets, you have been accessing the columns and rows ascollections in the hierarchy.In a typed DataSet, you can access these directlyas objects, as shown in the following example:MessageBox.Show(pubs.Publishers(0).pub_id)Typed DataSets also provide compile-time type checking and betterperformance than untyped DataSets.DataSets created using the XML Designer tools are automatically typed.Note 54 Module 8: Using ADO.NETDataSets and XmlDataDocumentsTopic ObjectiveTo provide an overview ofXSLT, X-Path, Controls, Designers,the relationship betweenSchema, DTD, etc.Code GenerationDataSets andXmlDataDocuments.Lead-insyncXmlDataDocument DataSetXML developers havetraditionally used the XMLDOM to manipulate theirXML documents.XmlReader XmlReader Managed ProviderXML Documents XML DocumentsData SourceXML developers have traditionally used the Document Object Model (DOM) toDelivery Tipmanipulate their XML documents.This is a standard COM interface to XMLThis topic is not meant todata, and it allows access to the elements and attributes contained within thecover how to usedocument.XmlDataDocuments but tosimply provide an overviewThe XmlDataDocument in the.NET Framework extends the DOMDocumentof the link with DataSets.object in the XML DOM to allow.NET developers to use the samefunctionality.This object is tightly integrated with the ADO.NET DataSet, andloading data into either object synchronizes it with the other.Any manipulation of data by means of the DataSet or the XmlDataDocumentis synchronized in the other.Therefore, if you add a row to the DataSet, anelement is added to the XmlDataDocument, and vice versa. Module 8: Using ADO.NET 55Demonstration: Using XML SchemaTopic ObjectiveTo demonstrate using XMLdocuments by means ofDataSets.Lead-inThis demonstration willshow you how to use anXML schema to validate andXML document.In this demonstration, you will learn how to create an XML schema from anexisting XML document, and how to then use the schema to validate thedocument. 56 Module 8: Using ADO.NETLab 8.1: Creating Applications That Use ADO.NETTopic ObjectiveTo introduce the lab.Lead-inIn this lab, you will useADO.NET to access data.Explain the lab objectives.ObjectivesAfter completing this lab, you will be able to:Retrieve, insert, and update data by using ADO.NET.Use data binding on a Web Form.Use the XML Designer to create a typed dataset.PrerequisitesBefore working on this lab, you must be familiar with:Creating Visual Basic.NET Windows Forms and Web Forms.Using ADO.NET data readers.Using ADO.NET DataSets.Working with XML and XSD.ScenarioIn this lab, you will use ADO.NET to access data for the Cargo application.You will create both Windows Forms and Web Forms that access bothcustomer and invoice information.You will also use the XML Designer tocreate a typed DataSet.Starter and Solution FilesThere are starter and solution files associated with this lab [ Pobierz całość w formacie PDF ]
  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • wblaskucienia.xlx.pl