|
|
|
|
Recordset Move Methods <%@ Language=VBScript %><% option explicit %> Dim conn Dim SQL dim R dim F Dim RecsAffected Dim aConnectionString aConnectionString="Provider=SQLOLEDB;Data " & "Source=(local);Database=ClassRecords ;" & "UID=sa;PWD=;" Set conn=Server.CreateObject("ADODB.Connection") conn.Mode=adModeRead conn.ConnectionString=aConnectionString conn.CursorLocation=adUseClient conn.open SQL = "SELECT * FROM Students ORDER BY LastName, FirstName" Set R = Server.Create0bject("ADODB.Recordset") R.Open SQL, conn, adOpenStatic, adLockReadOnly, adCmdText Response.Write "<b>By default, when you first open a " & "Recordset object, it's positioned at the first " & "record.</b><br>" Response.Write "First Record: " & R("LastName") & ", " & R("FirstName") & "<br>" Response.Write "<b>Moved to the last record.</b><br>" R.moveLast Response.Write "Last Record: " & R("LastName") & ", " & R("FirstName") & "<br>" Response.Write "<b>Moved to the previous record.</b><br>" R.MovePrevious Response.Write "Next-To-Last Record: " & R("LastName") & ", " & R("FirstName") & "<br>" R.MoveFirst Response.Write "<b>Moved to the first record.</b><br>" R.MoveNext Response.Write "<b>Moved to the next record.</b><br>" Response.Write "Second Record: " & R("LastName") & ", " & R("FirstName") & "<br>" Response.Write "<br>" Response.Write "<h3>All Records</h3>" R.MoveFirst Response.Write "<table align='left' border='1'>" Response.Write "<tr>" For Each F In R.Fields Response.Write "<td>" & F.Name & "</td>" Next Response.Write "</tr>" While Not R.EOF Response.Write "<tr>" For Each F In R.Fields Response.Write "<td>" & F.Value & "</td>" Next Response.Write "</tr>" R.Move Next Wend Response.Write "</table>" R.Close Set R = Nothing conn.Close Set conn = Nothing %> |