This example uses the Recordset object's Find method to locate and display the companies in the Northwind database whose name begins with the letter G.
<!-- BeginFindJS --> <%@ Language=JavaScript %> <!-- Include file for JScript ADO Constants --> <!--#include File="adojavas.inc"--> <html> <head> <title>ADO Recordset.Find Example</title> <style> <!-- BODY { font-family: 'Verdana','Arial','Helvetica',sans-serif; BACKGROUND-COLOR:white; COLOR:black; } .thead { background-color: #008080; font-family: 'Verdana','Arial','Helvetica',sans-serif; font-size: x-small; color: white; } .thead2 { background-color: #800000; font-family: 'Verdana','Arial','Helvetica',sans-serif; font-size: x-small; color: white; } .tbody { text-align: center; background-color: #f7efde; font-family: 'Verdana','Arial','Helvetica',sans-serif; font-size: x-small; } --> </style> </head> <body bgcolor="white"> <h1>ADO Recordset.Find Example</h1> <!-- Page text goes here --> <% myConnect = "Provider=sqloledb;Data Source=" + Request.ServerVariables("SERVER_NAME") + ";" + "Initial Catalog=Northwind;User Id=sa;Password=;"; mySQL = "select * from Customers;"; showblank = " "; shownull = "-null-"; var connTemp = Server.CreateObject("ADODB.Connection"); connTemp.Open(myConnect); var rsTemp = Server.CreateObject("ADODB.Recordset"); rsTemp.ActiveConnection = connTemp; rsTemp.CursorLocation = adUseClient; rsTemp.CursorType = adOpenKeyset; rsTemp.LockType = adLockOptimistic; rsTemp.Source = mySQL; rsTemp.Open(); rsTemp.MoveFirst(); rsTemp.Find("CompanyName like 'g%'"); if (rsTemp.EOF) { Response.Write("No records matched "); Response.Write(mySQL & "So cannot make table..."); connTemp.Close(); Response.End(); } else { Response.Write('<table width="100%" border="2">'); Response.Write('<tr class="thead2">'); // Put Headings On The Table for each Field Name for (thisField = 0; thisField < rsTemp.Fields.Count; thisField++) { fieldObject = rsTemp.Fields(thisField); Response.Write('<th width="' + Math.floor(100 / rsTemp.Fields.Count) + '%">' + fieldObject.Name + "</th>"); } Response.Write("</tr>"); while (!rsTemp.EOF) { Response.Write('<tr class="tbody">'); for(thisField=0; thisField<rsTemp.Fields.Count; thisField++) { fieldObject = rsTemp.Fields(thisField); strField = fieldObject.Value; if (strField == null) strField = shownull; if (strField == "") strField = showblank; Response.Write("<td>" + strField + "</td>"); } rsTemp.Find("CompanyName like 'g%'", 1, adSearchForward) Response.Write("</tr>"); } Response.Write("</table>"); } rsTemp.Close(); connTemp.Close(); %> </body> </html> <!-- EndFindJS -->
Find Method | Recordset Object