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

ASP
bbs的树状结构算法
bbs的树状算法的补充程序
ASP.NET:访问Excel 电子表格
ADO.NET:ADODataReader类
ADO.NET:使用ADO.NET连接文本文件
session变量中的数组如何引用
外源.js的选择调用与一个.htm网站管理初探
验证email地址是否合法完整实例
不用Global.asa实现在线人数统计
为输入及输出的数据库的资料做造型
改进性能和样式的 25+ ASP 技巧(1)
改进性能和样式的 25+ ASP 技巧(2)
改进性能和样式的 25+ ASP 技巧(3)
改进性能和样式的 25+ ASP 技巧(4)
表单递交内容检测脚本-这里只接受数字
如何使replace方法不区分大小写?
在 Web 页上使用条件数值格式
如何用asp把sqlserver数据转换为execl文件
用ADO STREAM做的无组件上传程序简单介绍
如何在主页中控制浏览权限

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 34 ::
收藏到网摘: 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
% >