ASP.NET 連接ACCESS數(shù)據(jù)庫的簡單方法
更新時間:2013年07月23日 10:33:35 作者:
一段非常簡單的連接ACCESS數(shù)據(jù)庫的實例代碼,有需要的朋友可以參考一下
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>
復(fù)制代碼 代碼如下:
<%@ 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>
您可能感興趣的文章:
- ASP.NET web.config中數(shù)據(jù)庫連接字符串connectionStrings節(jié)的配置方法
- asp.net連接查詢SQL數(shù)據(jù)庫并把結(jié)果顯示在網(wǎng)頁上(2種方法)
- ASP.NET 6種常用數(shù)據(jù)庫的連接方法
- ASP.NET2.0 SQL Server數(shù)據(jù)庫連接詳解
- ASP.NET連接數(shù)據(jù)庫并獲取數(shù)據(jù)方法總結(jié)
- ASP.NET連接MySql數(shù)據(jù)庫的2個方法及示例
- ASP.NET中操作SQL數(shù)據(jù)庫(連接字符串的配置及獲取)
- asp.net連接數(shù)據(jù)庫 增加,修改,刪除,查詢代碼
- ASP.NET連接 Access數(shù)據(jù)庫的幾種方法
- ASP.NET WebAPI連接數(shù)據(jù)庫的方法
相關(guān)文章
淺談.Net Core 認(rèn)證系統(tǒng)源碼解析
這篇文章主要介紹了淺談.Net Core 認(rèn)證系統(tǒng)源碼解析,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-12-12ASP.NET Core程序發(fā)布到Linux生產(chǎn)環(huán)境詳解
這篇文章主要為大家詳細(xì)介紹了ASP.NET Core程序發(fā)布到Linux生產(chǎn)環(huán)境,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-04-04asp.net實現(xiàn)DataList與Repeater嵌套綁定的方法
這篇文章主要介紹了asp.net實現(xiàn)DataList與Repeater嵌套綁定的方法,結(jié)合實例形式分析了DataList與Repeater的步驟與相關(guān)實現(xiàn)技巧,需要的朋友可以參考下2016-04-04asp.net 長文章通過設(shè)定的行數(shù)分頁
長文章通過設(shè)定的行數(shù)來實現(xiàn)分頁的代碼。2009-12-12asp.net 計算字符串中各個字符串出現(xiàn)的次數(shù)
比如一個字符串"a,b,a,c,b,b,d",現(xiàn)在我們要統(tǒng)計每個字符串出現(xiàn)次數(shù)。解決這個問題,我們可以使用泛型集合 Dictionary(TKey,TValue)。它有一個key值用來存儲字符串和一個value值,用來存儲字符串出現(xiàn)的次數(shù)2012-05-05