Académique Documents
Professionnel Documents
Culture Documents
Objectives
In this lesson, you will learn to:
• Map XML to databases
• Implement various query languages
• Display data from multiple tables using VC#
• Mappings form the basis for data transfer between XML documents
and databases. Following are the two types of mappings:
• Table-Based Mapping
• Query Languages
• Object-Relational Mapping
• Query languages are embedded in XML document and are used for
data transfer between applications.
Best Practices
Applying 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
FAQs
• When using the SqlDataReader, how do you know the number of records
that are found?
This is the same type of problem we had back in classic ADO where the
Recordset's 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.
•
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.
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 .
FAQs(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"
FAQs(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.
Challenge
Challenge (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)
Challenge (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)
Solution to Challenge
Summary
• 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