随笔-211  评论-26  文章-8  trackbacks-0

使用ODBC连接时代码如下:
<%@ language=Jscript%>         //记住这是在jscript条件下的数据库连接
<html>
     <body>
           <ul>
               <%
                      var conn=Server.CreateObject("ADODB.Connection");
                       conn.Opent("driver={Microsoft Access Driver (*.mdb)};dbq=" +
                      Server.Mappath("database/user.mdb"));
                         rs = conn.Execute("select * from user");
                       for(i=0;i<rs.Fields.Count;i++)
                           {
                                 Response.Write("<li>"+rs(i).Name);
                           }
                        conn.close();
          %>
      <ul>
   <body>
<html>
使用OLEDB连接时代码如下
<%@ language=Jscript %>
<html>
   <body>
   <%
          var conn=Server.CreateObject("ADODB.Connection");
          conn.Open("Provider=Microsoft.Jet.OLEDB.4.0;" + "DataSource=" +   Server.MapPath("database/user.mdb"));
      rs=conn.Execute("select * from [user]");
       for(i=0;i<rs.Fields.Count;i++)
            {
                 Response.Write("<li>"+rs(i).Name);
             }
          conn.close();
      %>
      </body>
</html>
        从上面两个代码中,我们可以看出,在oledb中,USER是系统关键字,因此我们引用时要加一个中括号,以免出现错误。

posted on 2006-07-12 16:56 dragon 阅读(60) 评论(0)  编辑  收藏 所属分类: asp学习日记