• Save
Vb.net session 16
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Vb.net session 16

on

  • 643 views

 

Statistics

Views

Total Views
643
Views on SlideShare
624
Embed Views
19

Actions

Likes
0
Downloads
0
Comments
0

1 Embed 19

http://niitcourseslides.blogspot.in 19

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Vb.net session 16 Presentation Transcript

  • 1. Mapping XML to DatabasesObjectives In this lesson, you will learn to: • Map XML to databases • Implement various query languages • Display data from multiple tables using VC# ©NIIT Creating Data Centric Applications Using ADO.NET Slide 1 of 18
  • 2. Mapping XML to DatabasesUnderstanding XML Data Transfer • XML can be used for transferring data from client-side application to a server side application and vice versa. Server can host a database or an application. The data transfer can happen between applications or application and database. XML data transfer can happen in the following ways: • Map XML to databases • Query Languages • Map XML to databases • Mappings form the basis for data transfer between XML documents and databases. Following are the two types of mappings: • Table-Based Mapping • Query Languages ©NIIT Creating Data Centric Applications Using ADO.NET Slide 2 of 18
  • 3. Mapping XML to DatabasesUnderstanding XML Data Transfer(Contd.) • Table-Based Mapping • Table-based mapping is used for data transfer between an XML document and a relational database. You can also transfer data between relational databases by using the table-based mapping. • Object-Relational Mapping • In the object-relational mapping, the data in the XML document is organized in a hierarchical manner. This type of mapping is used by mostly XML-enabled relational databases such as SQL server. ©NIIT Creating Data Centric Applications Using ADO.NET Slide 3 of 18
  • 4. Mapping XML to DatabasesUnderstanding XML Data Transfer(Contd.) • Query Languages • Query languages are embedded in XML document and are used for data transfer between applications. • Template-Based Query Languages Construction • SQL-Based Query Languages • XML Query Languages ©NIIT Creating Data Centric Applications Using ADO.NET Slide 4 of 18
  • 5. Mapping XML to DatabasesDisplaying Data from Multiple Tablesusing VC# • Consider an example. An application needs to be created to display a Windows Form. The form should display a combo box that comprises all Customer IDs. When a user selects a customer ID, the corresponding order IDs should be displayed in a list box. • To create an application for the above scenario, perform the following steps: • Create a Windows application • Add a combo box and list box to the form • Connect to the database • Create the data adapters and connections • Generate the Dataset that will contain the related data tables ©NIIT Creating Data Centric Applications Using ADO.NET Slide 5 of 18
  • 6. Mapping XML to DatabasesDisplaying Data from Multiple Tablesusing VC#(Contd.) • Create the Relationship. • Fill the combo box with customer Ids. • Fill the dataset with data from the Customers and the Orders table. • Create an event handler to retrieve the order details for a selected customer. • Display the related records in the list box. • Follow easy to understand naming conventions for the system and processes. • Design the system in such a manner that it meets the immediate system requirements and can be modified later for enhanced features. • Test the modules. ©NIIT Creating Data Centric Applications Using ADO.NET Slide 6 of 18
  • 7. Mapping XML to Databases From the Expert’s Desk • This section provides: • Best practices on ADO.NET and Data Access Components • Tips and Tricks • FAQs on Data Binding and Data Reader. ©NIIT Creating Data Centric Applications Using ADO.NET Slide 7 of 18
  • 8. Mapping XML to DatabasesBest PracticesApplying Best Practices to a Project • The best practices that you can follow in a project are: • Use the Appropriate Data-Access Object • Use SQL Data Types With SQL Server • Use Centralized Data-Access Functions • Use Centralized Data-Access Functions ©NIIT Creating Data Centric Applications Using ADO.NET Slide 8 of 18
  • 9. Mapping XML to DatabasesTips and TricksEstablishing Quick Database Connection in .NET • While establishing connection to a database, you may find problems in creating the database connection string. Following sites provide connection strings that can be used in the applications • http://www.connectionstrings.com • http://www.able-consulting.com/ADO_Conn.htm ©NIIT Creating Data Centric Applications Using ADO.NET Slide 9 of 18
  • 10. Mapping XML to DatabasesFAQs • When using the SqlDataReader, how do you know the number of records that are found? The SqlDataReader provides means of reading a "forward-only" stream of rows from a SQL Server database. Therefore, the number of rows read from the database is not known until the last row is read. This is the same type of problem we had back in classic ADO where the Recordsets RecordCount was always -1 for a server-side, forward-only cursor. The solution in classic ADO was to use a static or keyset cursor. Or use a client-side cursor location, which always used a static cursor. However in ADO.NET 1.0, there is no such thing as a server-side, static or keyset cursor. There is only the server-side, forward-only DataReader. Or there is the client-side, static DataSet. •    ©NIIT Creating Data Centric Applications Using ADO.NET Slide 10 of 18
  • 11. Mapping XML to Databases FAQs(Contd.) You can work-around this issue by either Increment a counter while looping through all of the rows, or use two SELECT statements in your query. The first one returns the row count and the second one returns the actual rows. e.g. "SELECT COUNT(*) FROM myTableName; SELECT * FROM myTableName". Then you can use the NextResult method to move from the first to the second result set, or use a DataSet instead of the SqlDataReader. Then use the DataSet‘s Table Rows count. e.g. DataSet.Tables("Products").Rows.Count. • How can I bind a data grid to a relationship through code? To bind a data grid to a relationship through code, you set the DataSource property to the dataset that contains the relationship, and you set the DataMember property to the relationship. You must refer to the relationship through its parent table . ©NIIT Creating Data Centric Applications Using ADO.NET Slide 11 of 18
  • 12. Mapping XML to DatabasesFAQs(Contd.) For example, suppose you define a relationship named SalesInvoices that relates rows in a parent table named Sales to rows in a child table named Invoices. Then, if the relationship and tables are stored in a dataset named DsPayables2, you can bind a data grid named grdInvoices to the relationship using this code: grdInvoices.DataSource = DsPayables2 grdInvoices.DataMember = "Sales.SalesInvoices" • Why do I get a "Login failed" error message when I try to connect to a SQL Server database from a web application? This error typically occurs while using Windows NT Integrated security to connect to the database. This error occurs because ASP.NET runs as a separate Windows process with its own login name: ASPNET. ©NIIT Creating Data Centric Applications Using ADO.NET Slide 12 of 18
  • 13. Mapping XML to DatabasesFAQs(Contd.) When you try to access a SQL Server database from a web application, then, ASP.NET will try to use this login name to log in to SQL Server. For that to work, you first have to create a Windows user named ASPNET, and you have to create a SQL Server user account named ASPNET and grant it access to the database. A simpler solution is not to use Windows NT Integrated security. Instead, you can name the specific SQL Server account you want to use when you create the connection. If you’re using MSDE on your own system, for example, you can probably just use the default system administrator account, sa. ©NIIT Creating Data Centric Applications Using ADO.NET Slide 13 of 18
  • 14. Mapping XML to DatabasesChallenge ©NIIT Creating Data Centric Applications Using ADO.NET Slide 14 of 18
  • 15. Mapping XML to DatabasesChallenge (Contd.) • Across: • 13. Used for connecting to a database, retrieving data, storing the data dataset, reading the retrieved data, and updating the database. (11) • 134. Method of DataTable class to filter data(6) • 142. Language used to define the elements and attributes of XML documents(3) • Down: • 2. Object that creates a fixed customized view of given DataTable object(8) • 4. Provides the bridge between the DataSet object and the data source. (11) • 7. Type of binding, to display multiple values for a column from the dataset rows(7) • 9. ADO.NET uses the ___________ data architecture(12) ©NIIT Creating Data Centric Applications Using ADO.NET Slide 15 of 18
  • 16. Mapping XML to DatabasesChallenge (Contd.) • 12. Component that represents the column that uniquely identifies a row in a DataTable(10) • 13. A recordset in ADO is similar to a _________ in ADO.NET (7) • 22. Used to retrieve data from a data source in a read-only and forward-only mode(10) • 39. Method used to stop the connection with a data source(5) • 41. Represents a table in the DataTableCollection of a dataset(9) • 54. Dataset, which does not have any associated XML schema(7) • 56. Control, which displays data from multiple records as well as multiple columns. (8) • 59. Data command to enter data into a database(6) • 79. Fundamental format for data transfer in ADO.NET(3) ©NIIT Creating Data Centric Applications Using ADO.NET Slide 16 of 18
  • 17. Mapping XML to DatabasesSolution to Challenge ©NIIT Creating Data Centric Applications Using ADO.NET Slide 17 of 18
  • 18. Mapping XML to DatabasesSummary • XML can be used for transferring data from client-side application to a server side application and vice versa. Server can host a database or an application. • XML data transfer can happen in the following ways: • Map XML to databases • Query Languages • Query languages are embedded in XML document and are used for data transfer between applications. • You can display data from multiple tables using VC# • The best practices that you can follow in a project are: • Use the Appropriate Data-Access Object • Use SQL Data Types With SQL Server • Use Centralized Data-Access Functions • Use Centralized Data-Access Functions ©NIIT Creating Data Centric Applications Using ADO.NET Slide 18 of 18