Data shaping (which can also be called Hierarchical recordsets)
If you are familiar with access, it is similar to a child table. When you use VB
Database development is the best choice for you.
This technology has a strong application environment, especially for the development of enterprise-class applications such as OLTP.
It allows you to use a tree-like structure to represent your data, so it is particularly suitable for
To display the associated data table Form to the user.
In simple terms, it has a master table (Recordset) and then
One of the fields in the master table can hold a second child table (Recordset)
Of course, in general, one of the fields in the child table (such as the primary index) and the field in the master table
is associated (relationship) so that when you execute a query, the result returns a
Multiple recordsets. This data shaping technology brings us the following benefits:
1. Performance improvement, as long as the rational use of this technology, can greatly improve
ASP connects the performance of the database program. And you don't have to show complicated
Interrelated data forms and worry about them.
2. Greatly simplifies programming: Because of the hierarchical Recordset structure it introduces,
Using the tree view to display records, you will find that you use the data shaping technology to display
The data is very beautiful.
Or the previous method, the nonsense less to say, let the code to speak put:
This example will use the example database in SQL Server, pubs
How to use data shaping programming:
The preparatory work is as follows:
1. You should install a MSDataShape OLE DB Provider (in MDAC2. More than 0 versions are available with this data source provider)
2. You should be able to write the shape language, note that this is not a general SQL statement, you can view the specific syntax
The Help file in Access.
A couple of places to pay attention to.
(i) Establishment of a MSDataShape OLE DB provider connectionstring as follows (hehe, it seems that my piece
The database connection manual can be added to the new stuff.
' This is a very common connection string, hehe, where the Kanga is actually SQL Server in Microsoft internal code
strconn = "Provider=sqloledb;data source=kanga;" &_
"Initial catalog=pubs; User Id=sa; Passwprd= "
' Well, now join the MSDataShape OLE DB provider section
strconn = "Provider=msdatashape; Data "& strconn
Well, now that you've set the data provider for MSDataShape,
Note that the data source provider is your real DSN section.
(II) Shape language
Shape syntax You can find detailed descriptions in the help of ADO, and I'm not wordy.
The most commonly used statements are as follows:
SHAPE {Parent Command} [as parent alias]
APPEND ({Child Command} [as child alias]
RELATE Parent_column to Child_column) [as Parent_column_name]
One of the simplest examples is as follows:
SHAPE {SELECT * from publishers}
APPEND ({SELECT * from Titles}
RELATE pub_id to pub_id) as Rstitles
The above statement associates the titles table with a child table of publishers, so how to access it
Data, the syntax is as follows:
Set rstitles = rspublishers ("Rstitles"). Value
Now the Rstitles is a recordset, which is the data in the child table.
The aspshape.asp file code is as follows:
<%
Dim rspublishers
Dim Rstitles
Dim Strshapeconn
Dim Strshape
Dim strconn
Set rspublishers = Server.CreateObject ("ADODB. RecordSet ")
Strshapeconn = "Provider=msdatashape; Data "& strconn
Strshape = "SHAPE {SELECT * from publishers}" & _
"APPEND ({SELECT * from Titles}" & _
"RELATE pub_id to pub_id) as Rstitles"
Rspublishers.open Strshape,strshapeconn
Response.Write "<UL>"
While not rspublishers.eof
Response.Write "<LI>" & Rspublishers ("Pub_name")
Response.Write "<UL>"
' Start displaying data for the child table below
Set rstitles = rspublsihers ("Rstitles"). Value
While not rstitles.eof
Response.Write "<LI>" & Rstitles ("title")
Rstitles.movenext
Wend
Response.Write "</UL>"
Rspublishers.movenext
Wend
Response.Write "</UL>"
Rspublishers.close
Set rspublishers = Nothing
Set rstitles = Nothing
%>
You can run the code above and then watch the results, and then the usual
Compare it with a SQL query.
Note: This is a time to add a bit of DHTML statement, can be made
The collection and expansion effects of the tree structure (similar to the one on the left of the resource manager)
Oh, this aspect fell off but very good at.
Oh, the above is just a very simple child table, the following brief introduction
The case of multiple child tables.
If you have only one child table in your datasheet, you can actually use SQL to do that.
It is not yet possible to fully display the advantages of the data shaping technology, but if your parent table
With multiple fields associated with other tables, you can fully see the technology
The power.
Here's an example of a two child table
SHAPE {SELECT * from publishers}
APPEND ({SELECT * from Titles}
RELATE pub_id to pub_id) as Rstitles,
({SELECT * from Employee}
RELATE pub_id to pub_id) as Rsemployees
Simple put, hehe.
This is nothing, you know. If you are in a datasheet
child table and child table (this is what is called a hierarchical Recordset)
You will find it more convenient to use the data shaping technology. That's why
I said at the beginning. This technology is particularly useful for the development of OLTP and enterprise-class complex databases.
Here is an example of a two-tier child table
SHAPE {SELECT * from publishers}
APPEND (SHAPE {SELECT * from Titles}
APPEND ({SELECT * from Sales}
RELATE title_id to title_id) as Rssales)
RELATE pub_id to pub_id) as Rstitles
In fact, not only can you use SQL statements in data shaping, but you can also use stored procedures.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.