当前位置: 首页 > 图文教程 > 网络编程 > ASP > 将ASP代码移植为VB COM组件-4

ASP
自动清空站点目录下所有文件
ASPEMAIL通过Mdaemon的SMTP发信-recipient unknow处理办法
使用split分割多字符的字符串的方法
ASP调用oracle存储过程
ASP访问INTERBASE数据库
利用Session限制重复操作的简单方法
一个socket组件及其调用方法
ASP模仿asp.net的DataGrid
利用ASP技术实现文件直接上传功能
微软建议的ASP性能优化28条守则
温柔的杀手—跨站ASP Script攻击
aspjpeg组件高级使用方法介绍
asp+sqlserver 分页方法(不用存储过程)
Windows 2003上传文件不能超过200k解决方法
一个比较实用的asp函数集合类
WebClasses使注册变得容易
ASP对FoxPro自由表(DBF文件)的操作
HTTP_REFERER的工作方式
抓取动网论坛Email地址的一段代码
ASP+FSO+框架实现ASP生成htm并分页的方法(批量)

将ASP代码移植为VB COM组件-4


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 58 ::
收藏到网摘: n/a

  这个例子中的第一站是ASP页。这个ASP页用ADO与Northwind 数据库连接。为了保持良好的编码习惯,我
使用了Option Explicit 并明确地声明了所有变量。这个ASP页的第一个草稿使用了内联代码。

< % @ LANGUAGE=VBScript % >
< %
    'Example of Inline code
    Option Explicit
    
    'Declare variables
    Dim oConn
    Dim oRS
    Dim ConnectionString
    Dim x
    
    ConnectionString = "DSN=Northwind;"
    
    Set oConn = Server.CreateObject("ADODB.Connection")
    oConn.Open ConnectionString
    
    Set oRS = Server.CreateObject("ADODB.Recordset")
    
    'Set variables
    oRS.ActiveConnection = oConn
    oRS.Source = "Select * from Products"
    oRS.Open
% >
< html >
< head >
< meta http-equiv="Content-Type" content="text/html; charset=windows-1252" >
< title >New Page 1< /title >
< /head >
< body >
< h1 >Products< /h1 >
< table cellspacing="2" cellpadding="5" >
    < tr bgcolor="#FF6666" >
        < th >Product Name< /th >
        < th >Quantity Per Unitr< /th >
        < th >Price< /th >
    < /tr >
    < %
        Do until oRS.EOF
            If x = 1 then
                x = 0
    % >
    < tr bgcolor="#ffcccc" >
    < % else % >
    < tr >
    < %
            x = 1
        end if
    % >
        < td >< %=oRS("ProductName")% >< /td >
        < td >< %=oRS("QuantityPerUnit")% >< /td >
        < td >< %=oRS("UnitPrice")% >< /td >
    < /tr >
    < %
            oRS.MoveNext
        Loop
    % >
< /table >
< /body >
< /html >
< %
    'Destroy objects
    Set oRS = Nothing
    Set oConn = Nothing
% >