For Web applications, make sure that you have a copy of adodb.dll in the Bin subfolder of the application's virtual directory. If your application lacks a virtual folder, place adodb.dll in the Web server's root directory (i.e., C:\inetpub\wwwroot\bin). After you have the correct file in place, you're ready to use ADODB.Recordset and other ADO objects from any .NET application. To see how to use ADO in .NET, let's consider a simple ASP.NET Web Forms page.
A Web Forms page is nothing more than a text file with an .aspx extension. So to write it, you don't strictly need Visual Studio .NET installed; any text editor (e.g., Notepad) will work fine. For this demonstration, I use Notepad as the editor and C# to code the sample application. First, you link the adodb.dll managed executable to the ASP.NET page by adding an @ Assembly directive at the top of the file:
<%@ Assembly Name="ADODB" %>
To call any object in the ADODB assembly, you must use the ADODB namespace prefix. So to create a new Recordset object, you must use the following syntax:
ADODB.Recordset adoRS = new ADODB.Recordset();
However, if you also add an ad hoc Import directive such as
<%@ Import Namespace="ADODB" %>
you can declare a Recordset object by using the following, more compact syntax:
Recordset adoRS = new Recordset();
From here on, you can write your code the ADO way. For example, to fetch a Recordset and walk through the returned records, you use the code that Listing 1 shows. This code is part of a sample application (which you can download at http://www.sqlmag.com, InstantDoc ID 24025) that fetches a Recordset and creates a series of check-box input controls. Figure 1 shows the output of the sample application. Listing 2 shows the main part of the codethe ImportAdo.aspx file.
Prev. page
1
[2]
3
4
next page