ASP.NET 链接数据库基础

发表于:2007-06-30来源:作者:点击数: 标签:
index.aspx %@PageLanguage="C#"% %@importNamespace="System.Data"% %@importNamespace="System.Data.OleDb"% scriptrunat="server" //Insertpagecodehere // voidPage_Load(){ stringdb=@"database/data.mdb"; stringconnStr="PROVIDER=Microsoft.Jet.OLED
  
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>

原文转自:http://www.ltesting.net