First, the GetRows use method:
<%
Set conn=server.createobject ("Adodb.connection")
Conn. Open "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & Server.MapPath ("Test.mdb")
Set rs=server.createobject ("Adodb.recordset")
Rs.Open "SELECT top 2 * from table name", conn,0,1
Dim Array_str
Array_str = Rs. GetRows ()
Response.Write "First record:<br>"
Response.Write Array_str (0,0) & "<br>"
Response.Write Array_str (1,0) & "<br>"
Response.Write Array_str (2,0) & "<br>"
Response.Write Array_str (3,0) & "<br>"
Response.Write "Second record:<br>"
Response.Write Array_str (0,1) & "<br>"
Response.Write Array_str (1,1) & "<br>"
Response.Write Array_str (2,1) & "<br>"
Response.Write Array_str (3,1) & "<br>"
%>
Familiar with GetRows you will find that the operation of the database is simpler, faster and more optimized. The advantages are many OH:
Second, is it necessary to declare variables?
You need to declare variables in the following situations:
1. You're a good programmer.
2. Write high quality code
Add the following code to force the declaration of a variable:
<%option explicit%>
How do I invoke a server-side function at the client?
Remote Scripting Call Technology (scripting) is characterized by the need to refresh the entire page when client script invokes the server script.
Typically, Web pages need to submit form data when interacting with the server, refreshing the entire page. Using remote scripting to invoke technology, client script can call remote script functions like local functions, especially in complex forms validation and frequent database operations, and this advantage is most vividly played.
Its rationale is that it uses a set of interface functions provided by itself that client programs can invoke server-side code through an agent process (a Java applet). Javaapplet (Rsproxy.class) works in the background, usually the user code does not need to directly manipulate it, and its configuration is automatically completed. A remote script call can be either a synchronous call---a call to a command that waits until the end of the server execution function, or it can be returned immediately after an asynchronous call---function call, and the call must also give the callback function. A basic remote scripting call technique must include the following files:
Rs.htm: Include client support code
Rsproxy.class: This is a Java applet that actually completes the client/server interaction process
Rs.asp: Server-side support code
When using remote scripting to invoke functionality, both client and server-side code must meet certain requirements: On the server side, you must first enable remote script calls: include rs.asp with #include, and invoke the Rsdispath function. The key to implementing remote scripting support on the server side is to create public_description objects. It differs from the normal ASP page execution process on a remote call, putting the global scripting code into a function and calling it explicitly.
Remote scripting calls technology requires that server-side scripts must use theJavaScriptWrite. The following example declares a description class that contains a common SAML function that creates a description, or Public_description object, with the new keyword.
1. Remote Scripting calls Object Server-side requirements:
<% @language =vbscript%>
<%RSDispatch%>
<!--#include file= ". /rs.asp "-->
<script language=JavaScriptRunat=server>
function Description () {
This.saml=saml;
}
Public_description=new description ();
function Saml (str) {
Return "hi!" + str + ": \ n Your sessionid=" + session.sessionid+ "\ n your ip=" +request.servervariables ("REMOTE_ADDR");
}
</Script>
2. Remote invoke function requirements on the client. First, the Web page that enables the remote scripting call technology feature must refer to rs.htm, and secondly, the rsenableremotescripting function must be invoked. The Rsenableremotescripting function allows you to specify the actual path where the Rsproxy.class file is located in the parameter, and the default is Rsproxy.class under the _ScriptLibrary directory:
<script language= "javascript" src= ". /rs.htm "></script>
<script language= "javascript" >rsenableremotescripting ("..."); </script>
3. Call the remote script. Once you have completed the above preparation, you can use the Rsexecute method to remotely invoke the server-side function in client code. The parameters accepted by this method include the URL of the server ASP page, the name of the remote function, and the parameter list. The result of the call is a Call object, which contains the return value of the call and the status information, whose primary properties include:
ID: The unique identity of the call (the property is actually an XML string);
Return_value: Actual return value, if present;
Data: The server responds to the original information returned by the remote call;
Status: Identifies the state of this call,-1 indicates failure, and 0 indicates completion.
Message: Textual information about this call. If the call succeeds, it is completed, otherwise, contains the error description.
Four, from the SQL database call picture display:
<% @language =vbscript%>
<%option explicit%>
<%
Dim conn,rs,pic,picsize
Response.buffer=true
' Set HTTP header information to allow the browser to interpret the data returned as a GIF image
Response.contenttype= "Image/gif"
Set Conn=server.createobject ("Adodb.connection")
Conn.Open "...........
Set Rs=server.createobject ("Adodb.recordset")
Rs.Open ".... ...", conn,0,1.....
PICSIZE=RS ("img"). ActualSize
PIC=RS ("img"). GetChunk (Picsize)
Response.BinaryWrite pic
Response.End
%>
The use of DLLs must be faster than the ASP code?
Not necessarily, in IIS5.0, ASP speed has been a certain increase, in many cases the ASP code to run faster than the use of DLLs. If the DLL code is not well written, it is often slower than the ASP. However, DLLs have a better advantage over ASP: Features, security, sharing, and so on.
How do I share the contents of an array between different pages?
a.asp File Contents:
<%
Dim arr (5)
Dim Str,i
' Assigning values to data
For i= 0 to 5
Arr (i) =i
Next
' Pass Array
Str=join (arr)
Response.Write "<a href=test.asp?tempstr=" & str & "> Transmit array content </a>"
%>
Test.asp content:
<%
Dim tempstr
Tempstr=split (Request ("str"), ",")
Response.Write TempStr (0) & "<br>" & TempStr (1)
%>
Vii. Usage of eval:
<%
M= "50+60+80"
Response.Write Eval (m)
%>
Viii. why does using a transaction prompt an error when ADO accesses a database?
Situation One:
Set Dbconn=server.createobject ("Adodb.connection")
Set Dbcmd=server.createobject ("Adodb.command")
Dbconn.open "dsn=sqlforum;uid=sa;pwd=;"
Dbconn. BeginTrans
Rs.Open "SELECT * from Message", Dbconn
Set Dbcmd.activeconnection=dbconn
The above statement prompts you with the following error message:
Unspecified Error
Situation Two:
Set Dbconn=server.createobject ("Adodb.connection")
Bconn.open "dsn=sqlforum;uid=sa;pwd=;"
Dbconn. BeginTrans
The above statement prompts you with the following information:
Cannot start transaction while in Firehose mode.
Situation Three:
Set Dbconn=server.createobject ("Adodb.connection")
Set Dbcmd=server.createobject ("Adodb.command")
Dbconn.open "dsn=sqlforum;uid=sa;pwd=;"
Rs.Open "SELECT * from Message", Dbconn
Set Dbcmd.activeconnection=dbconn
Dbconn. BeginTrans
The above statement prompts you with the following information:
Cannot start transaction because more than one HDBC was in use.
What's going on? How to solve?
"Firehose" refers to a read-only cursor pattern. When we open the recordset without specifying a cursor type, the recordset opens with a forward cursor, which we call "Firehose" when used with SQL Server. This connection will open all the time, and the query results will open as soon as possible, and this read-only method cannot perform the transaction.
The reason for this error, as in the previous cases, is that the ActiveConnection cursor pattern of the Command object is readonly in "firehose" mode.
There are several ways to change "firehose":
1. The cursor type that sets the connection is not read forward.
2. Close the Recordset object that uses the same connection before starting the transaction.
nine, with insert into or addnew? The
AddNew essentially encapsulates Insert into, so the speed is slower than Insert into.