ASP.NET 连接ACCESS数据库的简单方法
程序员文章站
2024-02-29 13:45:40
index.aspx复制代码 代码如下:<%@ page language="c#" %><%@ import namespace="system.dat...
index.aspx
<%@ 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">
<!-- insert content here -->
</form>
</body>
</html>
复制代码 代码如下:
<%@ 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">
<!-- insert content here -->
</form>
</body>
</html>