当前位置: 移动技术网 > IT编程>开发语言>.net > asp.net快速连接access

asp.net快速连接access

2017年12月12日  | 移动技术网IT编程  | 我要评论

香港机房托管,伟胜dv影视,孝感人事网

大家都等着急了吧,直接上方法

1、确定asp.net的文档头部语句<%@ page language="c#" %>

2、引用数据库语句:

<%@ import namespace="system.data" %>
<%@ import namespace="system.data.oledb" %>

3、建立一个数据库:data.mdb

4、js代码script语句的编写:

<script runat="server">
  // insert page code here
  //
  void page_load(){
    string db=@"database/data.mdb";
    string connstr="provider=microsoft.jet.oledb.4.0;data source="+server.mappath(db)+";";
    string sqlcmd="create table ieb_webs(id identity primary key,title varchar(255) default null)";
    oledbconnection conn=new oledbconnection(connstr);
    conn.open();
    oledbcommand olecmd=new oledbcommand(sqlcmd,conn);
    olecmd.executenonquery();   //执行sql命令
    response.write("数据表建立完成!");
    }
    conn.close();
    conn=null;
    olecmd=null;
  }
</script>

5、把js语句写入html文本中

<html>
<head>
</head>
<body>
  <form method="post" runat="server">
    <!-- 此地调用数据库内容 -->
  </form>
</body>
</html>

6、最后完整的代码结构如:

<%@ page language="c#" %>
<%@ import namespace="system.data" %>
<%@ import namespace="system.data.oledb" %>
<script runat="server">
  // insert page code here
  //
  void page_load(){
    string db=@"database/data.mdb";
    string connstr="provider=microsoft.jet.oledb.4.0;data source="+server.mappath(db)+";";
    string sqlcmd="create table ieb_webs(id identity primary key,title varchar(255) default null)";
    oledbconnection conn=new oledbconnection(connstr);
    conn.open();
    oledbcommand olecmd=new oledbcommand(sqlcmd,conn);
    olecmd.executenonquery();   //执行sql命令
    response.write("数据表建立完成!");
    }
    conn.close();
    conn=null;
    olecmd=null;
  }
</script>
<html>
<head>
</head>
<body>
  <form method="post" runat="server">
    <!-- 此地调用数据库内容 -->
  </form>
</body>
</html>

以上就是asp.net连接access既快速又简单的办法,希望大家能够按照我分享的步骤实现asp.net与access的连接。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网