1. How to Use GetRows:
<%
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 "the 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>"
%>
If you are familiar with GetRows, you will find that database operations are simpler and faster. There are many advantages :)
2. Is it necessary to declare variables?
Variables must be declared in the following cases:
1. You are a good programmer
2. Write high-quality code
Add the following code to force declare a variable:
<% Option Explicit %>
3. How do I call server functions on the client?
Remote Scripting does not need to refresh the entire page when client scripts call server scripts.
Generally, form data must be submitted to refresh the entire page when a Web page needs to interact with the server. Using Remote scripting, client scripts can call remote scripting functions like calling local functions, especially in complex form verification and frequent database operations, this advantage has been fully realized.
Its basic principle is that it uses a set of interface functions provided by itself, the client program can call the server code through a proxy process (a java applet. Java Applet (RSProxy. class) works in the background. Generally, the user code does not need to be operated directly, and its configuration is also automatically completed. A remote script call can be a synchronous call. The call command waits until the server executes the function and returns it. It can also be an asynchronous call, the callback function must be provided at the same time. A Basic remote script call technology must contain the following files:
RS.htm: Contains code supported by the client
RSProxy. class: This is a Java Applet that completes the customer/server interaction process.
RS. asp: code supported on the server
When using the remote script call function, both client and server code must meet certain requirements: on the server side, you must first enable remote script call: Use # include to include RS. asp, and call the RSDispath function. The key to implementing Remote Script support on the server is to create a public_description object. The script execution process is different from the normal ASP page execution process during Remote calls. It puts the global script code into the function and calls it explicitly.
Remote script calling technology requires that scripts on the server must be usedJavascriptWrite. The following example declares a Description class, which contains a common saml function. You can use the new keyword to create a Description, that is, the public_description object.
1. Requirements for remote scripts to call the Object Server:
<% @ 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 address = "+ Request. ServerVariables (" REMOTE_ADDR ");
}
</Script>
2. Client Requirements for the remote call function. First, enable remote scripts to call the webpage interface of technical functions to call rs.htm. Second, you must call the RSEnableRemoteScripting function. The RSEnableRemoteScripting function allows you to specify the actual path of the RSProxy. class file in the parameter. If this parameter is not specified, RSProxy. class is in the _ scriptLibrary directory by default:
<Script language ="Javascript"Src =" ../rs.htm "> </script>
<Script language ="Javascript"> RSEnableRemoteScripting ("... "); </script>
3. Call a remote script. After completing the preceding preparations, you can use the RSExecute method to remotely call server functions in the client code. Parameters accepted by this method include the URL of the Server ASP page, the remote function name, and the parameter list. The Call result is a Call Object that contains the returned value and status information of the Call. Its main attributes include:
Id: the unique identifier of the Call (the attribute is actually an XML string );
Return _Value: Actual return value, if any;
Data: the server responds to the original data returned by the Remote Call;
Status: indicates the status of this call.-1 indicates failure, and 0 indicates completion.
Message: The text information about this call. If the call is successful, it is Completed. Otherwise, it contains an error description.
4. Call Image Display from SQL database:
<% @ Language = VBscript %>
<% Option Explicit %>
<%
Dim conn, rs, pic, picsize
Response. Buffer = True
'Set the http header information so that the browser can interpret the data returned as gif images.
Response. ContentType = "image/gif"
Set conn = server. createobject ("adodb. connection ")
Conn. open "................."
Set rs = server. createobject ("adodb. recordset ")
Rs. open "......", conn
Picsize = rs ("img"). actualsize
Pic = rs ("img"). getchunk (picsize)
Response. binarywrite pic
Response. end
%>
5. Is it faster to use DLL than ASP code?
Not necessarily. In IIS5.0, ASP speed has been improved. In many cases, ASP code runs faster than DLL. If the DLL code is not well written, it is often slower than ASP. However, DLL has better advantages than ASP, such as functions, security, and sharing.
6. How to share array content between different pages?
A. asp file content:
<%
Dim arr (5)
Dim str, I
'Assign a value to the data
For I = 0 to 5
Arr (I) = I
Next
'Pass the Array
Str = join (arr)
Response. Write "<a href = test. asp? Tempstr = "& str &"> transfer array content </a>"
%>
Test. asp content:
<%
Dim tempstr
Tempstr = split (Request ("str "),",")
Response. write tempstr (0) & "<br>" & tempstr (1)
%>
VII. Eval usage:
<%
M = "50 + 60 + 80"
Response. write eval (m)
%>
8. Why is an error prompted when using transactions when accessing the database through ADO?
Scenario 1:
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 following error message is displayed:
Unspecified error
Scenario 2:
Set dbconn = server. createobject ("adodb. connection ")
Bconn. open "dsn = sqlforum; uid = sa; pwd = ;"
Dbconn. BeginTrans
The preceding statement prompts the following information:
Cannot start transaction while in firehose mode.
Case 3:
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 preceding statement prompts the following information:
Cannot start transaction because more than one hdbc is in use.
What's going on? How can this problem be solved?
"Firehose" refers to a read-only cursor mode. When we open Recordset without specifying the cursor type, the Recordset will open with a forward cursor. When we connect to SQLserver, we call it "firehose ". The connection is always opened, and the query result is opened as soon as possible. In this read-only mode, transactions cannot be executed.
The cause of the above errors is that in the "firehose" mode, the activeconnection cursor mode of the command object is readonly.
There are several ways to change "firehose:
1. Set the cursor type of connection not to forward read-only.
2. Close the recordset object that uses the same connection before starting the transaction.
9. Using Insert into or Addnew?
Addnew encapsulates Insert into, so the speed is slower than Insert.