首页 > 编程 > .NET > 正文

ASP.NET 链接数据库基础

2024-07-10 12:56:30
字体:
来源:转载
供稿:网友
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 [email protected]"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>


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表