Recommended: How to implement Asp and Asp.Net share session In .net, the storage mechanism of Session is different from that of Asp. Although it can run asp and aspx at the same time under the same IIS, Session cannot be passed between them. Previously, a large number of systems were used to asp. During the upgrade process, if the asp is completely abandoned
Using the same idea as creating a universal connection in a separate module, we create a Pagelet. Pagelet enables developers to create pseudo-controls, which can be used to display properties, methods, and events as well as objects. Our solution is to create a Pagelet that displays the ConnectToDB method, which returns an ADOConnection object (slightly different from ADO's syntax). We use the following code to create a Pagelet and save it as connect.aspc (the extension indicates that it is a Pagelet)< %@ Import Namespace=System.Data %>
< %@ Import Namespace=System.Data.ADO %>
<script language=VB runat=server>
Public Function ConnectToDB() As ADOConnection
ConnectToDB = New ADOConnection(DSN=evilleDSN)
End Function
< /script>
You will notice that we imported two Namespaces, namely System.Data and System.Data.ADO. These Namespaces are required in order to use the ADO Managed Provider. Many people have asked me a lot of questions about this, because most of the examples currently use SQL Managed Provider based on Microsoft SQL Server 2000 database. For non-SQL Server databases, ASP can use ADO Managed Provider, which is roughly the same way you currently use ADO in your program. Importing Namespaces is similar to creating references in VB programs.
The use of Pagelet allows me to maintain my current site plan, and once a connection is created in the module, we can reuse the module wherever we need it. This means we need to replace the Include file directive with an instance of Pagelet, and then call the ConnectToDB method when we need a database connection. In a page that requires a Pagelet, we must first register it with the page using the ASP directive. In the directive, we define TagPrefix, TagName, and Source(src). Similar to the include file in ASP, TagPrefix and TagName should be used where we place the Pagelet.
< %@ Register TagPrefix=seven TagName=Connect
src=http://www.alixixi.com/Dev/Web/ASP/asp_1/2007/_includes/connect.aspc %>
The method of placing the Pagelet we just registered is similar to the ASP server control:
< [TagPrefix]:[TagName] id=myPagelet runat=server />
for example:
< seven:Connect id=Connect runat=server />
In ADO, the concept of record sets is replaced by a combination of DataSets and DataViews. We will discuss these two concepts later. First, let's see what changes have occurred after the default.asp page is moved to default.aspx (the suffix of the ASP page). Let's look at default.asp first:
< !-- #include file=_includes/connect.inc -->
< %
Dim cnEville_DB, rsUpcoming, strSqlUpcoming
Set rsUpcoming = Server.CreateObject(ADODB.Recordset)
strSqlUpcoming = SELECT TOP 2 & _
Classes.Title, Sessions.Session_ID, & _
Sessions.Special, Classes.Description & _
FROM Classes INNER JOIN Sessions ON & _
Classes.Class_ID = Sessions.ClassID & _
WHERE (((Sessions.Date)>Date())) & _
ORDER BY Sessions.Date
rsUpcoming.Open strSqlUpcoming,cnEville_DB
%>
In ASP it becomes default.aspx:
< %@ Import Namespace=System.Data %>
< %@ Import Namespace=System.Data.ADO %>
< %@ Register TagPrefix=seven TagName=Connect &_
src=http://www.alixixi.com/Dev/Web/ASP/asp_1/2007/_includes/connect.aspc %>
<script language=vb runat=server>
Sub Page_Load(Source As Object, E As EventArgs)
Dim dscUpcoming As ADODataSetCommand
Dim dsUpcoming As New DataSet
Dim strSQL As String
strSQL = SELECT TOP 2 Classes.Title, & _
Sessions.Session_ID, Classes.Description & _
FROM Classes INNER JOIN Sessions ON & _
Classes.Class_ID = Sessions.ClassID & _
WHERE (((Sessions.Date)>Date())) & _
ORDER BY Sessions.Date
dscUpcoming = New ADODataSetCommand(strSQL, Connect.ConnectToDB())
dscUpcoming.FillDataSet(dsUpcoming, Upcoming)
End Sub
< /script>
The core of data access, ANSI-SQL statements have nothing after conversion
Share: Discussion on the control status and view status of ASP.NET 2.0 Basic concepts Control status - In order for the control to work properly, sometimes the control status data is required. For example, if you write a custom control with different tabs showing different information, in order for the control to work as expected, the control needs to know that it has been round-trip through