明輝手游網(wǎng)中心:是一個(gè)免費(fèi)提供流行視頻軟件教程、在線學(xué)習(xí)分享的學(xué)習(xí)平臺(tái)!

ASP.NET 鏈接數(shù)據(jù)庫基礎(chǔ)

[摘要]index.aspx<%@ Page Language="C#" %><%@ import Namespace="System.Data" %><%@ import Namespace="System.Data.Ole...

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();      //執(zhí)行SQL命令

        Response.Write("數(shù)據(jù)表建立完成!");
        }

        conn.Close();
        conn=null;
        OleCmd=null;


    }

</script>
<html>
<head>
</head>
<body>
    <form method="post" runat="server">
        <!-- Insert content here -->
    </form>
</body>
</html>