CommandTimeOut <% Option Explicit Dim conn set conn = server.createobject ("adodb.connection") conn.open "ASPBook", "sa", "yourpassword" Response.Write "The default time out value is: " & Conn.CommandTimeout _ & " seconds.
" conn.CommandTimeout = 60 Response.Write "It has been changed to: " & Conn.CommandTimeout _ & " seconds.
" %> Default DB <% Option Explicit Dim conn set conn = server.createobject ("adodb.connection") conn.open "ASPBook", "sa", "yourpassword" Response.Write "The name of the default database in this SQL Server " _ connection is: " & Conn.DefaultDatabase conn.close conn.open "EmpsDatabase", "Admin", "" Response.Write "
The name of the default database in this Microsoft Access " _ & connection is: " & Conn.DefaultDatabase %> State <% Option Explicit Dim conn set conn = server.createobject ("adodb.connection") Response.Write "The current state of the connection is: " & Conn.State conn.open "ASPBook", "sa", "yourpassword" Response.Write "
The current state of the connection is: " & Conn.State conn.close Response.Write "
The current state of the connection is: " & Conn.State %> Transactions <% Option Explicit Dim conn Dim RS set conn = server.createobject ("adodb.connection") conn.open "AspBook", "sa", "yourpassword" set RS = conn.execute("select * from tblEmps where LastName = 'Doe'" _ & " and FirstName = 'Jane'") If RS.EOF Then Response.Write "
No Jane Doe in the database." Else Response.Write "
Jane Doe was found!" End If conn.close conn.open "AspBook", "sa", "yourpassword" conn.BeginTrans conn.execute "insert into tblEmps (FirstName, LastName) values (" _ & "'Jane', 'Doe')" conn.RollBackTrans set RS = conn.execute("select * from tblEmps where LastName = 'Doe'" _ & " and FirstName = 'Jane'") If RS.EOF Then Response.Write "
No Jane Doe in the database." Else Response.Write "
Jane Doe was found!" End If conn.close conn.open "AspBook", "sa", "yourpassword" conn.BeginTrans conn.execute "insert into tblEmps (FirstName, LastName) values (" _ & "'Jane', 'Doe')" conn.CommitTrans set RS = conn.execute("select * from tblEmps where LastName = 'Doe'" _ & " and FirstName = 'Jane'") If RS.EOF Then Response.Write "
No Jane Doe in the database." Else Response.Write "
Jane Doe was found!" End If %> Execute <% Option Explicit Dim conn Dim RSEmps Dim NumRecordsModified set conn = server.createobject ("adodb.connection") conn.open "AspBook", "sa", "yourpassword" conn.Execute "Update tblEmps set LastName = 'Smith'", NumRecordsModified Response.Write "The update query affected " & NumRecordsModified _ & " records." set RSEmps = conn.execute("Select EmpID, LastName from tblEmps") Do Until RSEmps.EOF Response.Write "
Employee ID: " & RSEmps("EmpID") _
& "
Last Name: " & RSEmps("LastName")
RSEmps.MoveNext
Loop
%>
Recordset
<%
Option Explicit
Dim ConnectString
Dim CurrentPage
Dim RSEmps
Dim I
If IsEmpty(Request.QueryString("PageNumber")) Then
CurrentPage = 1
Else
CurrentPage = cint(Request.QueryString("PageNumber"))
End If
ConnectString = "DSN=EmpsDatabase;User Id=Admin;Password=;"
set RSEmps = Server.CreateObject("ADODB.Recordset")
RSEmps.CursorLocation = 3
RSEmps.Open "tblEmps", ConnectString, , , 2
RSEmps.PageSize = 3
RSEmps.AbsolutePage = CurrentPage
Do Until RSEmps.AbsolutePage <> CurrentPage or RSEmps.EOF
Response.Write RSEmps("LastName") & ", " & RSEmps("FirstName") _
& "
" RSEmps.MoveNext Loop Response.Write "Select page to view more employee records: " For I = 1 to RSEmps.PageCount Response.Write "" & I & " " Next %> Empty Recordset <% Option Explicit Dim Conn Dim RSVisitor set conn = server.createobject ("adodb.connection") conn.open "EmpsDatabase", "Admin", "" set RSVisitor = conn.execute("select VisitorID from Visitors where " _ & "UserName = '" & Request.Form("UserName") & "' and " _ & "Password = '" & Request.Form("Password") & "'") If RSVisitor.EOF Then 'Invalid log in Else 'Valid log in End If %> Cache <% Option Explicit Dim ConnectString Dim RSEmps ConnectString = "DSN=EmpsDatabase;User Id=Admin;Password=;" set RSEmps = Server.CreateObject("ADODB.Recordset") Response.Write RSEmps.CacheSize & "
" RSEmps.CacheSize = 5 Response.Write RSEmps.CacheSize %> Sort and Filter <% Option Explicit Dim ConnectString If IsEmpty(Session("RSEmps")) Then ConnectString = "DSN=EmpsDatabase;User Id=Admin;Password=;" set Session("RSEmps") = Server.CreateObject("ADODB.Recordset") Session("RSEmps").CursorLocation = 3 Session("RSEmps").Open "tblEmps", ConnectString, , , 2 Else Session("RSEmps").MoveFirst If Not Isempty(Request.Form("Requery")) Then Session("RSEmps").Sort = Request.Form("SortField") If Request.Form("Filter") = "All" Then Session("RSEmps").Filter = "EmpID > 0" Else Session("RSEmps").Filter = "EmpID = " & Request.Form("Filter") End If End If End If Response.Write "
Employee ID | First Name | " _ & "Last Name |
" & Session("RSEmps")("EmpID") & " | " Response.Write "" & Session("RSEmps")("FirstName") & " | " Response.Write "" & Session("RSEmps")("LastName") & " | " Response.Write "
" & MyField.Name & " | " Next Response.Write "
" & RSEmps(MyField.Name) & " | " Next Response.Write "
" Next %>