16. Connect ASP to Access database:
<%@ language=VBs cript%>
<%
dim conn,mdbfile
mdbfile=("Database name.mdb")
set conn=("")
"driver={microsoft access driver (*.mdb)};uid=admin;pwd=database password;dbq="&mdbfile
%>
Next, I hope everyone will participate in the recent
-------------------------------
Examples of useful asp programming (II)
17. Connect ASP to SQL database:
<%@ language=VBs cript%>
<%
dim conn
set conn=("")
"PROVIDER=SQLOLEDB;DATA SOURCE=SQL server name or IP address;UID=sa;PWD=database password;DATABASE=database name
%>
Create a record set object:
set rs=("")
SQL statement,conn,3,2
18. Common SQL command usage methods:
(1) Data record filtering:
sql="select * from data table where field name = field value order by field name [desc]"
sql="select * from data table where field name like '%field value %' order by field name [desc]"
sql="select top 10 * from data table where field name order by field name [desc]"
sql="select * from data table where field name in ('value 1','value 2','value 3')"
sql="select * from data table where field name between value 1 and value 2"
(2) Update data records:
sql="update data table set field name = field value where conditional expression"
sql="update data table set field 1=value 1, field 2=value 2... Field n=value n where conditional expression"
(3) Delete data records:
sql="delete from data table where conditional expression"
sql="delete from data table" (delete all records in the data table)
(4) Add data records:
sql="insert into data table (field 1, field 2, field 3…) valuess (value 1, value 2, value 3…)"
sql="insert into target data table select * from source data table" (add the record of the source data table to the target data table)
(5) Data record statistics function:
AVG (field name) to obtain an average value of a table column
COUNT (*field name) Statistics on the number of data rows or statistics on the number of data rows with values in a certain column
MAX (field name) Get the maximum value of a table column
MIN (field name) Get the minimum value of a table column
SUM (field name) adds the value of the data column
Reference the above function method:
sql="select sum(field name) as alias from data table where conditional expression"
set rs=(sql)
Use rs("alias") to obtain the statistics, and other functions are used the same as above.
(5) Establishment and deletion of data tables:
CREATE TABLE Data table name (field 1 type 1 (length), field 2 type 2 (length)…)
Example: CREATE TABLE tab01(name varchar(50), datetime default now())
DROP TABLE Data table name (permanently delete a data table)
19. Methods of record set objects:
Move the record pointer down one row from the current position
Move the record pointer up one line from the current position
Move the record pointer to the first row of the data table
Move the record pointer to the last row of the data table
=N Move the record pointer to row N of the data table
=N Move the record pointer to the first line of page N
=N Set each page to N records
Returns the total number of pages according to the pagesize setting
Returns the total number of records
Return whether the record pointer exceeds the head of the data table. True means yes, false is no
Return whether the record pointer exceeds the end of the data table. True means yes, false is no
Delete the current record, but the record pointer does not move downward
Add records to the end of the data table
Update data table records
---------------------------------------
20 Recordset object method
Open method
Source,ActiveConnection,CursorType,LockType,Options
Source
The Recordset object can be connected to the Command object through the Source property. The Source parameter can be a Command object name, a SQL command, a specified data table name, or a Stored Procedure. If this parameter is omitted, the system uses the Source property of the Recordset object.
ActiveConnection
The Recordset object can be connected to the Connection object through the ActiveConnection property. The ActiveConnection here can be a Connection object or a string parameter containing database connection information (ConnectionString).
CursorType
The CursorType parameter of the Open method of the Recordset object indicates what cursor type to start the data, including adOpenForwardOnly, adOpenKeyset, adOpenDynamic and adOpenStatic, which are described as follows:
--------------------------------------------------------------
Constant Constant Value Description
-------------------------------------------------------------
adOpenForwardOnly 0 Default value, start a cursor that can only move forward (Forward Only).
adOpenKeyset 1 Starts a Keyset type cursor.
adOpenDynamic 2 Start a Dynamic type cursor.
adOpenStatic 3 Starts a Static type cursor.
-------------------------------------------------------------
The above cursor types will directly affect all properties and methods of the Recordset object. The following list explains the difference between them.
-------------------------------------------------------------
Recordset property adOpenForwardOnly adOpenKeyset adOpenDynamic adOpenStatic
-------------------------------------------------------------
AbsolutePage Not supported Not supported Readable Writeable Readable Write
AbsolutePosition Not supported Not supported Readable Writeable Readable Write
ActiveConnection Readable and write Readable and write Readable and write Readable and write
BOF Read-only Read-only Read-only Read-only
Bookmark does not support Not supported Readable Writeable Readable Write
CacheSize Readable and write Readable and write Readable and write Readable and write
CursorLocation Readable and write Readable and write Readable and write Readable and write
CursorType Readable and write Readable and write Readable and write Readable and write
EditMode Read-only Read-only Read-only Read-only
EOF Read-only Read-only Read-only Read-only
Filter Readable and write Readable and write Readable and write Readable and write
LockType Readable and write Readable and write Readable and write Readable and write
MarshalOptions Readable and write Readable and write Readable and write Readable and write
MaxRecords Readable and write Readable and write Readable and write Readable and write
PageCount Not supported Not supported Read only Read only
PageSize Readable and write Readable and write Readable and write Readable and write
RecordCount is not supported Not supported Read only Read only
Source Readable and write Readable and write Readable and write Readable and write
State Read-only Read-only Read-only Read-only
Status Read-only Read-only Read-only Read-only
AddNew Support Support Support Support
CancelBatch Support Support Support Support
CancelUpdate Support Support Support Support
Clone Not supported Not supported
Close Support Support Support Support Support
Delete Support Support Support Support
GetRows Support Support Support Support
Move Not Support Support Support Support Support
MoveFirst Support Support Support Support
MoveLast Not Supported Support Support Support
MoveNext Support Support Support Support
MovePrevious Not supported Support Support Support Support
NextRecordset Support Support Support Support Support
Open Support Support Support Support Support
Requery Support Support Support Support Support
Resync does not support Not supported Support Support
Supports Support Support Support Support
Update Support Support Support Support Support
UpdateBatch Support Support Support Support Support
--------------------------------------------------------------
The NextRecordset method is not applicable to Microsoft Access databases.
LockType
The LockType parameter of the Open method of the Recordset object indicates the Lock type to be adopted. If this parameter is ignored, the system will use the LockType property of the Recordset object as the preset value. The LockType parameters include adLockReadOnly, adLockPrssimistic, adLockOptimistic and adLockBatchOptimistic, etc., and are described as follows:
-------------------------------------------------------------
Constant Constant Value Description
--------------------------------------------------------------
adLockReadOnly 1 Default value, the Recordset object is started in read-only mode, and the AddNew, Update, Delete and other methods cannot be run.
adLockPrssimistic 2 When the data source is being updated, the system temporarily locks other users' actions to maintain data consistency.
adLockOptimistic 3 When the data source is being updated, the system will not lock other users' actions. Other users can add, delete and modify the data.
adLockBatchOptimistic 4 When the data source is being updated, other users must change the CursorLocation property to adUdeClientBatch to increase the data.
Delete and modify operations.
Set your website as a trusted site for customers - WSH solution
ar SiteName="Acmnet"
SetTrustSite(SiteName);
("You have accept 'http://acmnet/' as your Trusted Site");
function SetTrustSite(StrSiteName)
{
var WshShell=("");
("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ZoneMap\\Domains\\"+StrSiteName+"\\http", 2 ,"REG_DWORD");
TrustedSite_Value=("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ZoneMap\\Domains\\"+StrSiteName+"\\http");
delete WshShell;
}
Previous page1234567891011121314151617181920Next pageRead the full text