[ Pobierz całość w formacie PDF ]
.DataBind(DataGrid1.DataBind( ))Most data displayed on Web Forms will be read only, so you do not need toincorporate the overhead of using a DataSet in your Web Form applications;you can use the more efficient DataReader object instead.If you want yourusers to be able to edit data on the Web Form, you must code the edit, update,and cancel events yourself.Binding to Read-Only DataYou use the DataBind method of the DataGrid server control to bind data to agrid on a Web Form.The following example shows how to do this using aDataReader object:Dim sqlconn As SqlClient.SqlConnectionDim da As SqlClient.SqlDataAdapterDim ds As New DataSet( )sqlconn = New SqlClient.SqlConnection( )sqlconn.ConnectionString = "Integrated Security=True;" & _"Data Source=LocalHost;Initial Catalog=Pubs;"sqlconn.Open( )Dim sqlComm As New SqlClient.SqlCommand("Select * from " & _"authors", sqlconn)Dim sqlReader As SqlClient.SqlDataReadersqlReader = sqlComm.ExecuteReaderDataGrid1.DataSource( ) = sqlReaderDataGrid1.DataBind( )The DataGrid will not be visible until you call the DataBind method. Module 8: Using ADO.NET 45XML IntegrationTopic ObjectiveTo provide an overview ofthe topics covered in thislesson.Why Use Schemas?Lead-inDescribing XML StructureXML is tightly integrated intothe.NET platform.Creating SchemasUsing XML Data and Schemas in ADO.NETDataSets and XmlDataDocumentsTraditionally, XML and ADO data have been two distinct entities, butDelivery TipADO.NET brings them together and allows you to work with both types in theThis lesson assumes thatsame way.students have reasonableknowledge of XML and anXML is tightly integrated into the.NET platform.You have already seen howawareness of its associatedDataSets are transmitted by using XML format, and now you will learn howtechnologies.DataSets are literally represented as XML and how their structure is defined inYou may find that you needan XML Schema Definition (XSD).to provide more backgroundinformation if students areAfter completing this lesson, you will be able to:not familiar with theseconcepts.Describe what an XML schemas is.Explain why XML schemas are useful to the Visual Basic.NET developer.Create schemas.Manipulate XML data within an ADO.NET DataSet by means of anXMLReader. 46 Module 8: Using ADO.NETWhy Use Schemas?Topic ObjectiveTo discuss XML schemasand the role they can play inVisual Basic.NET.Define Format of DataLead-inUse for Validity CheckingXML schemas are anessential part of theAdvantages over DTDsdeveloper s tool kit.XML syntaxReusable typesGroupingWhen working with traditional database applications, you often need to writevalidation code to ensure that the data you are inputting matches the databaseschema.If you do not do this, then you need to write error-handling code forthe potential errors that may occur.Either way, there must be some way ofchecking.The solution to this problem when you are working with XML data isXML schemas.XML schemas are similar in concept to database schemas.They define theelements and attributes that may appear in your XML documents, and howthese elements and attributes relate to each other.Schemas are very importantto ensure that the data you are using conforms to your specification.Whenloading XML data, you can check it against the schema to validate that none ofthe data entering your system is in an incorrect format.This is becoming moreof an issue as business-to-business and business-to-customer commercebecomes more prevalent in the Internet world. Module 8: Using ADO.NET 47Visual Studio.NET uses XSD to create schemas.This syntax is currently atworking-draft status at the World Wide Web Consortium (W3C), but it hasmany advantages over document type definitions (DTDs).XML syntaxDelivery TipIf students are not familiar DTDs are written using a DTD syntax, which is not related to any of thewith DTDs, do not spend tooother Internet standards currently in use.XSD uses XML syntax, whichmuch time justifying the useenables developers to validate data without needing to learn yet anotherof a new technology tolanguage.them.Reusable typesXSD allows you to define complex data types and reuse those within yourschema.GroupingYou can specify that a set of elements always exists as a group and stipulatethe order in which they must appear. 48 Module 8: Using ADO.NETDescribing XML StructureTopic ObjectiveTo explain how a schemadocument describes XMLdata.Schemas Can Describe:Lead-inElements in the documentSo, what is contained in theschema document?Attributes in the documentElement and attribute relationshipsData typesThe order of the elementsWhich elements are optionalSchemas describe the structure of an XML document, and you can use them tovalidate data within that document.A schema document can describe all orsome of the following:Elements and attributes contained within the XML documentElement and attribute relationshipsData typesThe order of the elementsWhich elements are optionalFor example, consider the following XML document:0736Lucerne PublishingBostonMAUSA0877Litware, Inc.WashingtonDCUSA Module 8: Using ADO.NET 49This document consists of a element containing individualelements.Each of these contains a , ,, , and element.This defines the structure of thedocument.After the XML document is linked to a schema document describin g thestructure, the schema can be used to verify data being input into the document.The following example shows the schema generated for this document: 50 Module 8: Using ADO.NETCreating SchemasTopic ObjectiveTo discuss how tocreate schemas inVisual Basic.NET.Creating Schemas from Existing XML DocumentsLead-inCreating Schemas from DatabasesSchemas can be generatedautomatically, or they canWorking with Schemasbe explicitly created.Validating XML Documents Against SchemaSchemas are automatically generated for you when you work with DataSets.You may find that there are situations when you want to create your own.Oneexample would be when you are exchanging data with a business partner andwant to define the structure of that data [ Pobierz całość w formacie PDF ]

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