Ado
Работа с ADO
Выполнение запроса с передачей данных через пареметры
Function WrLog(sText)
   Dim cmd
   set cmd = Server.CreateObject("ADODB.Command")
   set cmd.ActiveConnection = GetConnection()
   cmd.CommandType = adCmdText
   cmd.CommandText = "insert tbl_logs(user_id,comment) values(?,?)"
   cmd.Prepared = true
   cmd.Parameters(0).Value = Session("User_ID")
   cmd.Parameters(1).Value = sText
   cmd.Execute     
   set cmd = Nothing
End Function
Передача параметров процедуре из сессии
 Dim strName,strItem,res

 Dim Cmd
 Set Cmd = Server.CreateObject("ADODB.Command")
 set Cmd.ActiveConnection = Cnn
 Cmd.CommandText = "xxsp_visitor_new"
 Cmd.CommandType = adCmdStoredProc
 Cmd.Parameters("@sys_lang")=Lang.LangID
   
 res=0
 For Each sessitem in Session.Contents
   strName = CStr(sessitem)
   If Left(strName,1) = regPref Then
     strName= Mid(strName,2)
     If strName <> "user_index" Then
	strItem= CStr("" & Session.Contents(sessitem))
	If len(strItem) > 0 Then

	    If Cmd.Parameters("@" & strName).Type = adVarChar Then
	      strItem= Left(strItem,Cmd.Parameters("@" & strName).Size-1)
	    End if
	
	    On Error Resume next
	    Cmd.Parameters("@" & strName)= strItem
	    If Err.number <> 0 Then 
		    Response.Write "<font color='red'>"
		    Response.Write strName & "=" & strItem & "<br>"
		    Response.Write Err.Description & "</font><br>"
		    res = -1
	    End if
	    On Error goto 0
	    If res < 0 Then Exit for
		End if  
    End if  
   End if	
 Next
	 
 If res = 0 Then
   Set rs= Cmd.Execute()
   res= CInt(rs("xm_error"))
 End if  
 Set Cmd= Nothing
Adox
Создание базы данных
Private oCat as ADOX.Catalog
Set oCat = New ADOX.Catalog
oCat.Create "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\new.mdb"
Создание таблицы
Dim oTable as new Table
oTable.Name = "MyTable"
oCat.Tables.Append oTable
Добавление поля
oCat.Tables("MyNewTable").Columns.Append "Field1", adInteger
Типы
Константа Значение Описание
adBigInt 20 Indicates an eight-byte signed integer (DBTYPE_I8).
adBinary 128 Indicates a binary value (DBTYPE_BYTES).
adBoolean 11 Indicates a boolean value (DBTYPE_BOOL).
adBSTR 8 Indicates a null-terminated character string (Unicode) (DBTYPE_BSTR).
adChapter 136 Indicates a four-byte chapter value that identifies rows in a child rowset (DBTYPE_HCHAPTER).
adChar 129 Indicates a string value (DBTYPE_STR).
adCurrency 6 Indicates a currency value (DBTYPE_CY). Currency is a fixed-point number with four digits to the right of the decimal point. It is stored in an eight-byte signed integer scaled by 10,000.
adDate 7 Indicates a date value (DBTYPE_DATE). A date is stored as a double, the whole part of which is the number of days since December 30, 1899, and the fractional part of which is the fraction of a day.
adDBDate 133 Indicates a date value (yyyymmdd) (DBTYPE_DBDATE).
adDBTime 134 Indicates a time value (hhmmss) (DBTYPE_DBTIME).
adDBTimeStamp 135 Indicates a date/time stamp (yyyymmddhhmmss plus a fraction in billionths) (DBTYPE_DBTIMESTAMP).
adDecimal 14 Indicates an exact numeric value with a fixed precision and scale (DBTYPE_DECIMAL).
adDouble 5 Indicates a double-precision floating-point value (DBTYPE_R8).
adEmpty 0 Specifies no value (DBTYPE_EMPTY).
adError 10 Indicates a 32-bit error code (DBTYPE_ERROR).
adFileTime 64 Indicates a 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601 (DBTYPE_FILETIME).
adGUID 72 Indicates a globally unique identifier (GUID) (DBTYPE_GUID).
adIDispatch 9 Indicates a pointer to an IDispatch interface on a COM object (DBTYPE_IDISPATCH).
Note This data type is currently not supported by ADO. Usage may cause unpredictable results.
adInteger 3 Indicates a four-byte signed integer (DBTYPE_I4).
adIUnknown 13 Indicates a pointer to an IUnknown interface on a COM object (DBTYPE_IUNKNOWN).
Note This data type is currently not supported by ADO. Usage may cause unpredictable results.
adLongVarBinary 205 Indicates a long binary value (Parameter object only).
adLongVarChar 201 Indicates a long string value (Parameter object only).
adLongVarWChar 203 Indicates a long null-terminated Unicode string value (Parameter object only).
adNumeric 131 Indicates an exact numeric value with a fixed precision and scale (DBTYPE_NUMERIC).
adPropVariant 138 Indicates an Automation PROPVARIANT (DBTYPE_PROP_VARIANT).
adSingle 4 Indicates a single-precision floating-point value (DBTYPE_R4).
adSmallInt 2 Indicates a two-byte signed integer (DBTYPE_I2).
adTinyInt 16 Indicates a one-byte signed integer (DBTYPE_I1).
adUnsignedBigInt 21 Indicates an eight-byte unsigned integer (DBTYPE_UI8).
adUnsignedInt 19 Indicates a four-byte unsigned integer (DBTYPE_UI4).
adUnsignedSmallInt 18 Indicates a two-byte unsigned integer (DBTYPE_UI2).
adUnsignedTinyInt 17 Indicates a one-byte unsigned integer (DBTYPE_UI1).
adUserDefined 132 Indicates a user-defined variable (DBTYPE_UDT).
adVarChar 204    Indicates a binary value (Parameter object only).
adVariant 200 Indicates a string value (Parameter object only).
adVarNumeric 12 Indicates an Automation Variant (DBTYPE_VARIANT).
Note This data type is currently not supported by ADO. Usage may cause unpredictable results.
adVarWChar 139 Indicates a numeric value (Parameter object only).
adWChar 202 Indicates a null-terminated Unicode character string (Parameter object only).
adVarBinary 130 Indicates a null-terminated Unicode character string (DBTYPE_WSTR).
Примеры конектов к базам
MS SQL
set cnn=server.CreateObject("adodb.connection")
cnn.ConnectionString="Provider=SQLOLEDB;Data Source=NTSRV;Initial Catalog=SEK;UID=vlad;PWD=F5iBr78E"
MS Access
set cnn=server.CreateObject("adodb.connection")
cnn.ConnectionString="Provider= Microsoft.Jet.OLEDB.4.0;Data Source= E:\AccessBases\base1.mdb;JetOLEDB:Database Password=passwd"
dBase
set cnn=server.CreateObject("adodb.connection")
cnn.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\apr\;Extended Properties=dBase IV;mode=Read|Write|Share Deny None"
В данном примере предпологается, что база данных - это набор файлов в папке D:\APR\. Название файла - это, по сути, название таблицы. Параметром Extended Properties указывается стандарт базы данных, список всех возможных значений этого параметра можно посмотреть в реестре:
[HKEY_LOCAL_MACHINE\Software\Microsoft\Jet\4.0\ISAM Formats]
set cnn=server.CreateObject("adodb.connection")
cnn.ConnectionString="Driver={Microsoft Visual FoxPro Driver};SourceType=DBF;SourceDb="
Безымянные параметры
set cm = Server.CreateObject("ADODB.Command")
set rs = Server.CreateObject("ADODB.Recordset")
cm.ActiveConnection = cn
cm.CommandText = "select * from t where lang = ?"
cm.Parameters.Append(cm.CreateParameter(,200,,3,lang))
rs.CursorType = 3 'adOpenStatic
rs.Open cm

Hosted by uCoz