當前位置:首頁 » 操作系統 » asp查詢access資料庫

asp查詢access資料庫

發布時間: 2025-03-23 19:08:43

⑴ ASP查詢ACCESS資料庫有時候出錯:「不能打開資料庫 ''。」

CONN 打開了一定要記得關閉 數據集也要記得關閉
最好就是在文件後面加代碼

<%
on error resume next
if conn.state=1 then
conn.close()
set conn= nothing
end if
%>

來釋放未處理的連接的關閉

⑵ 簡單的asp加access讀取資料庫怎麼做

新建access資料庫時,任意打開一個access資料庫,點擊「文件」--「新建」-----"空資料庫"資料庫就創建好了!

在資料庫中可以選擇如何去創建表!

思路:

1.做一個注冊頁面,包含一個表單。表單中兩個文本框用來輸入用戶名密碼

2.一個注冊驗證頁面。用來判斷用戶名是否存在,並將注冊信息寫入表

我的注冊頁面和asp處理頁面是分開的分兩個文件reg.asp和zhuceyanzheng.asp

以下代碼是reg.asp文件的代碼

<scriptlanguage="javascript">

functioninput(){

varusername1=document.getElementById("username").value;

varpassword1=document.getElementById("password").value;

varpassword2=document.getElementById("password2").value;

if(username1==""){

alert("請輸入用戶名");

returnfalse;

}

if(password1==""){

alert("密碼不能為空!");

returnfalse;

}

if(password2!=password1){

alert("密碼不一致!請重新輸入");

returnfalse;

}

returntrue;

}

</script>

<body>

<formaction="zhuceyanzheng.asp"method="post"onsubmit="returninput()">

<!--action="zhuceyanzheng.asp"這一步是將表單注冊的值傳到zhuceyanzheng.asp頁面-->

<h2>注冊會員</h2>

用戶名:

<inputtype="text"name="username"id="username"value=""/>

<br/>

密碼:

<inputtype="password"name="password"id="password"value=""/>

<br/>

重新輸入密碼:

<inputtype="password"name="password2"id="password2"value=""/><br/>

<inputtype="submit"value="提交"/>

</form>

以下是zhuceyanzheng.asp的代碼

<%

dimusername,password,conn,rs,a

a=0

username=request("username")

password=request("password")

setconn=server.CreateObject("adodb.connection")

conn.connectionstring="provider=microsoft.jet.oledb.4.0;datasource="&server.mappath("user.mdb")

conn.open

setrs=server.CreateObject("adodb.recordset")

rs.open"select*from會員表",conn,1,3

dowhilenotrs.eof

ifusername=rs("用戶名")then

a=1

response.Write("<scriptlanguage='javascript'>alert('用戶名存在,請重新輸入');location.href('reg.asp');</script>")

endif

rs.movenext

loop

ifa=0then

rs.addnew

rs("用戶名")=username

rs("密碼")=password

rs.update

response.Write("<scriptlanguage='javascript'>alert('注冊成功,請登陸');location.href('login.asp');</script>")

endif

rs.close

setrs=nothing

%>

以下是zhuceyanzheng.asp頁面的代碼!這個頁面的功能是先用JavaScript驗證用戶名是否存在!如果不存在就把記錄寫到「會員表」中!

<%

dimusername,password,conn,rs,a

a=0

username=request("username")

password=request("password")

setconn=server.CreateObject("adodb.connection")

conn.connectionstring="provider=microsoft.jet.oledb.4.0;datasource="&server.mappath("user.mdb")

conn.open

setrs=server.CreateObject("adodb.recordset")

rs.open"select*from會員表",conn,1,3

dowhilenotrs.eof

ifusername=rs("用戶名")then

a=1

response.Write("<scriptlanguage='javascript'>alert('用戶名存在,請重新輸入');location.href('reg.asp');</script>")

endif

rs.movenext

loop

ifa=0then

rs.addnew

rs("用戶名")=username

rs("密碼")=password

rs.update

response.Write("<scriptlanguage='javascript'>alert('注冊成功,請登陸');location.href('login.asp');</script>")

endif

rs.close

setrs=nothing

%>

⑶ asp如何連接access資料庫

它的各步驟及參數意義如下:
第一行程序:利用Server對象的MapPath函數,取得要打開資料庫的完整的文件路徑,並存儲在變數DbPath中。這其中,資料庫名是我們需要指定的參數,應該用我們要打開的資料庫的實際名稱替代。如果資料庫名是直接作為常量出現,要用引號將其括起來,並且不能丟掉擴展名。例如資料庫是Test.mdb,則該行程序成為:DbPath=Server.MapPath(「Test.mdb」)。
第二行程序:建立一個ADO對象集中的Connection對象,也即連接對象。這是建立資料庫連接的初始步驟。執行這行程序後,Conn成為一個連接對象。
第三行程序:利用連接對象Conn的Open方法打開一個指定的資料庫。因為我們要打開的是Access資料庫,所以要指定ODBC驅動程序參數,表示要透過Access的ODBC驅動程序來訪問資料庫:driver={Microsoft
Access
Driver
(*.mdb)};。另一個參數dbq=
&
DbPath,運算後等效於dbq=Server.MapPath(資料庫名)
,是利用了第一行的Server.MapPath(資料庫名)函數,用來指定要打開的資料庫文件。到這里,就已經打開了資料庫名指定的資料庫。如果資料庫名是「test.mdb」,則打開Access資料庫Test.mdb。在這一行里指定的參數,要嚴格按照格式原樣寫出,不能省略或改動,也沒有可變參數。

熱點內容
phpfile亂碼 發布:2025-07-16 03:57:54 瀏覽:93
手機存儲空間擴容 發布:2025-07-16 03:52:07 瀏覽:861
小米4清除緩存 發布:2025-07-16 03:03:17 瀏覽:563
如何緩解壓力英語作文 發布:2025-07-16 03:03:15 瀏覽:15
手機視頻怎麼緩存 發布:2025-07-16 02:59:05 瀏覽:933
安卓手機設備在哪裡找 發布:2025-07-16 02:49:28 瀏覽:357
php建立數組 發布:2025-07-16 02:34:30 瀏覽:284
oracle存儲過程同步 發布:2025-07-16 02:29:18 瀏覽:941
歐諾s買哪個配置的好 發布:2025-07-16 02:26:22 瀏覽:559
熱點可以建立ftp嗎 發布:2025-07-16 02:26:21 瀏覽:304