Often asked questions (FAQ) about ASP
The present{true} description grows out personal experiments and supervision of the author and does not apply for completeness, accuracy and vseob``emlemost`. For the sake of availability some terms and calculations are given in the simplified kind. Whenever possible such places are supplied with links to more detailed description.
1. Difference of the description of methods in vbscript and javascript
In what I at once vljapalsja when has conceived to translate asp-files from vbscript on javascript, this difference of syntactic registration of methods in different scripts - languages. If in vbscript the line worked:
rs. MoveNext
That in javascript a corresponding line
rs. MoveNext;
Gave out a strange mistake such as " object does not support the given property or a method ". " With what stati does not support? " - I for a long time enough wondered, have not guessed yet to attribute a pair of brackets:):
rs. MoveNext ();
2. How to limit kol-in deduced{removed} lines at performance of search?
To thrust result of search in a file of the necessary size; to give out on the screen contents of a file. An example:
<% ' Opening of a database, formation of search.
Set Conn = Server. CreateObject ("ADODB.Connection")
Conn. Open "ADOSamples" sql = " SELECT * FROM Orders "
Set RS = Conn. Execute (sql) %> <TABLE BORDER=1> <TR>
<% For i = 0 to RS.Fields. Count - 1 ' a conclusion of names of fields of %>
<TD> <B> <% = RS (i) .Name %> </B> </TD> <% Next of %> </TR>
<% ' To place the first 100 lines of search in a 2-dimensional variant-file v=RS.GetRows (100)
RS.close ' To close object such as RecordSet Conn.close ' to close object such as Connection %>
3. A useful trick: how to organize a conclusion of objects (for example, pictures) in the table on them URL'am
To call in appropriate way a name of the field containing URL, for example URLimage.
During a conclusion given to check a name of a field on presence podstroki "URL" and depending on it to deduce{remove} contents of a field as the text either as the link, or as object which this link specifies. An example:
<% ' Note: The following is a bit of a hack... If the column name contains '
the string "URL" anywhere in it, assume it is a URL to a gif or jpg '
file and generate the HTML to get the image and display. This works '
for the Products table in the Adventure Works database, but is not a '
general purpose solution. If InStr (RS (i) .Name, "URL")>
0 Then Response. Write " <img src = "" " and RS (i) and ""> "
Else Response. Write RS (i) End If %>
4. To be cautious with RecordCount
The quantity{amount} of recordings in the received search can be defined{determined} with the help property RecordCount:
<% sql = " SELECT * FROM Orders " Set RS = Conn. Execute (sql) RS.RecordCount %>
However this value can be equaled-1 only that ADO in a used configuration cannot define{determine} quantity{amount} of lines.
5. Inverted commas
Esli in search line values it is better to use ' (apostrophe), instead of " (a double apostrophe) are used. In spite of the fact that in ISQL/w both searches equally are carried out, in asp (perhaps in it it is guilty javascript) the double apostrophe causes a mistake. For example better so:
<% sql = " SELECT * FROM Orders WHERE id = ' " +id + "'"; %>
Instead of so:
<% sql = " SELECT * FROM Orders WHERE id = " " +id + "" "; %>
6. Attention: types char and varchar
Cravnivaja such as char I could not achieve value of the variable received from the filled form, and the table taken from a field, that javascript have considered their equal though externally they looked completely identical. And with other variables was it's OK. Appeared, that they were compared to fields such as varchar. Having recollected almost forgotten knowledge of types of fields subd oracle, I have come to a conclusion that the type char which value has length such what have declared for a field is guilty. Value such as varchar has length according to contained line.
Having tormented with definition of length of a variable, I have decided, that it is the best way to not use in tables type char without special necessity.
7. Concerning length of a line
The variables received from the form in the way:
name = Request.form ("name");
Or from a database:
sql = " SELECT name, passw, email FROM persons WHERE email = ' " +email + "'"; rs = conn. Execute (sql); name = rs (0);
On a question name.length respond it "is not known". When I nevertheless had necessity for definition of length of such values, I have acted{arrived} so:
var name = " "; name + = Request.form ("name"); var name = " ";
sql = " SELECT name, passw, email FROM persons WHERE email = ' " +email + "'";
rs = conn. Execute (sql); name + = rs (0);
8. It is better to use property .value
It is necessary to be cautious with objects Recordet. If in html still it is possible to deduce{remove} a variable so:
<% rs = conn. Execute (sql); %> <% = rs (0) %>
That, working with a variable, is possible to run into troubles. For example, expression
(rs (0) == name)
Will give out "lie" that at a conclusion both values will be identical. To make so more correctly:
(rs (0) .value == name)
9. " If RecordSet is, it at once no... "
Again about care with objects Recordet. We admit{allow} cause stored{kept} procedure:
CREATE PROCEDURE do_test1 @num int AS select * from test where num = @num return 100
At some option values @num the given procedure will give out one or a line from the table test, and at others - to not give out any. If we will address to rs, received, for example, in such a way:
rs = conn. Execute (" do_test1 1 "); rs. Close ();
That, any troubles will not arise.
If procedure will look thus:
CREATE PROCEDURE do_test2 @num int AS if @num = 1 select
* from test where num = @num return 100 else return 200
That operators:
rs = conn. Execute (" do_test2 1 "); rs. Close ();
From hands will leave, and:
rs = conn. Execute (" do_test2 0 "); rs. Close ();
Will call a mistake on Close ():
ADODB.Recordset error ' 800a0e78 ' Invalid operation on closed object.

|