當前位置:首頁 » 操作系統 » asp資料庫調用

asp資料庫調用

發布時間: 2022-05-31 00:56:15

『壹』 ASP代碼如何調用資料庫數據

首先需要連接資料庫,access還是sql是不同的請度娘。我只說說你後面的問題。在連接成功後存在一個conn
(
看到了樓主的是rsClassBm
,請替換即可
)調用的方法按照樓主的則是<%set
rsnews=conn.execute("select
*
from
ArtBigClass")do
while
not
rsnews
.eof
%>"><%=
rsnews("BigClassName")
%><%
rsnews.movenext
loop%>

『貳』 asp網頁中如何調用mdb資料庫。

找到「數據源(ODBC)」並且打開,點擊「系統DSN」-「添加」-「Microsoft Access Driver(*.mdb)」

(註明:如果使用的Access 2007以上的版本,資料庫文件後綴名為.accdb時,這里應該選擇Microsoft Access Driver(*.mdb,*accdb))-「完成」-填入數據源名稱-「選擇」-找到你的資料庫,並確定-「確定」。

『叄』 如何用ASP調用資料庫種數據

<%
dim
connstr
set
conn=server.createobject("adodc.connection")
connstr="DRIVER={SQL
sever
(*.db)};Defausltdir=;DBQ="+"server.mappath("這里是資料庫文件的地址")"
conn.open
connstr
%>
如上是連接資料庫了,如果要做導航的話,得調用資料庫的內容,那要再上面文件加上這些
set
recordset1=server.createobject("adodc.recordset")
這句是創建數據集
比如你的導航有一項是news,那你可再加上
recordser1.open()
在導航欄用<%response.write(recordset1.fields.item("news").value)%>

『肆』 asp中如何調用資料庫圖片,麻煩仔細點,謝謝!

你沒有說清是什麼資料庫,先說說access吧。

如何從ACCESS資料庫中讀取images
1。ACCESS和FoxPro資料庫中的圖形格式
當瀏覽器遇到一個<IMG>標志時,它會根據你設定的src屬性來下載文件。
這可能是一個圖形文件或則是一個ASP頁面。
如果是一個返回gif二進制的ASP頁面
瀏覽器需要知道返回的是什麼格式的圖形文件
因為這個原因,就需要指定content type,為image/gif,image/bmp
image/jpeg或則其他什麼的。
Response.contentType = "image/gif"
但這會導致另外一個問題,那就是我們只能夠顯示gif格式的圖象,
或則說保存在資料庫中的東西只能夠是gif格式的了。
但是一些資料庫是使用gif格式保存的,但是另外一些則是使用
jpeg格式保存的,甚至其他是採用OLE方式來保存圖形的。
所以我們必須根據圖形的格式來設置response的content type.

注意的是你也可以從一個文件中新建一個點陣圖對象,但使用這樣
的方式保存在資料庫中的圖形格式是瀏覽器不能夠識別的。
當你往資料庫中保存圖象時,你應該知道你需要使用什麼格式來保存
你可以把文件中的每一個位元組保存下來,或則通過ACCESS/Foxpro的把圖形保存
為一個OLE格式。
你使用什麼格式保存圖象決定了你在ASP中用什麼格式來讀出圖形來。
具體來說,如果你在ACCESS/FoxPro中將圖形保存為bmp,gif,jpeg(
這個必須要使用到ACCESS/FoxPro的OLE對象,即使用ACCESS的插入對象
對話框來完成),這是當你使用
image/bmp時瀏覽器是不能夠解釋的。

現在假設在資料庫中保存的是你所想要的圖形格式
(GIF, JPEG, BMP, TIFF, 等)現在來看看要怎麼把它們從
資料庫中讀出來。

在ACCESS中使用了兩個關鍵的技術來保存圖形
1。使用了bmp格式
2。78個位元組的文件頭

<%
response.Expires = 0
response.Buffer = True
response.Clear
response.contentType = "image/bmp"
%>
接著你要乾的就是去掉那78個位元組的OLE對象的文件頭。
<%
Const OLEHEADERSIZE = 78
nFieldSize = rs("photo").ActualSize
oleHeader = rs("photo").GetChunk(OLEHEADERSIZE)
imageBytes = rs("photo").GetChunk(nFieldSize - OLEHEADERSIZE)
Response.BinaryWrite imageBytes
%>

現在舉一個例子:
如果你要得到一個職工的信息,這段信息包括一個介紹和他的圖象。
並且要同時顯示文字和圖形。
代碼如下:(其中的theImg是一個代理頁面)
theImg.asp
<%
response.Expires = 0
response.Buffer = True
response.Clear
response.contentType = Session("ImageType")
response.BinaryWrite Session("ImageBytes")
Session("ImageType") = ""
Session("ImageBytes") = ""
response.End
%>

Function SetImageForDisplay(field, contentType)
OLEHEADERSIZE = 78
contentType = LCase(contentType)
select case contentType
case "gif", "jpeg", "bmp"
contentType = "image/" & contentType
bytes = field.value
case "ole"
contentType = "image/bmp"
nFieldSize = field.ActualSize
oleHeader = field.GetChunk(OLEHEADERSIZE)
bytes = field.GetChunk(nFieldSize - OLEHEADERSIZE)
end select
Session("imageBytes") = bytes
Session("imageType") = contentType
End Function
'注意的是,程序中只使用了4中格式:gif, jpeg, bmp , ole .

<%
sql = "select * from Employees"
Set oRS = Server.CreateObject("ADODB.Recordset")
oRS.CursorLocation = 3
oRS.Open sql, "DSN=NW"
SetImageForDisplay oRS("photo"), "ole"
Set oRS.ActiveConnection = Nothing
%>

要顯示圖象的話,只需要在另外一個asp中,假設為getEmpInfo.asp中
<img src="theImg.asp"</img>
但這還有一個問題,因為對每個職工的圖形都使用了同一個"theImg.asp"
文件,應該再小小修改一下:
<img src="theImg.asp?temp=<%= Request.Form("empLastName")%>"</img>

最後再說一點,如何顯示多幅圖象呢?
也就是說如果資料庫中有多個欄位都保存了圖形,怎麼辦?
其實解決辦法很簡單,只要給SetImageForDisplay多加一個參數
就是用來保存圖形的一個session變數。
例如:
SetImageForDisplay oRS1("photo"), "ole", "empPhoto"
SetImageForDisplay oRS2("logo"), "gif", "compLogo"

<img src="theImg2.asp?varName=empPhoto&temp=<%= Request.Form("empLastName")%>">
<img src="theImg2.asp?varName=compLogo&temp=<%= Request.Form("imgCode")%>">

使用這個方法能夠完成下面的功能:
1。能夠從資料庫中取出圖形欄位。(你唯一需要知道的是資料庫中的圖形是什麼格式
bmp?gif?jpeg?ole?)
2.採用session變數 來保存圖形的位元組數和content type
asp需要這些信息來聯結到<IMG>中的屬性
3。只要把theImg放到你想顯示圖形的地方,就能夠顯示圖象了

『伍』 ASP問題,如何調用資料庫數據

首先需要連接資料庫,access還是SQL是不同的請度娘。我只說說你後面的問題。在連接成功後存在一個conn
(
看到了樓主的是rsClassBm
,請替換即可
)調用的方法按照樓主的則是<%set
rsnews=conn.execute("select
*
from
ArtBigClass")do
while
not
rsnews
.eof
%>"><%=
rsnews("BigClassName")
%><%
rsnews.movenext
loop%>

『陸』 ASP調用SQL資料庫

serch.asp

<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>無標題文檔</title>
<style type="text/css">
<!--
.thin { border-collapse: collapse;
}
.STYLE2 {font-size: 12px; color: #000000; }
-->
</style>
</head>

<body>
<table width="80%" border="0" align="center" cellpadding="1" cellspacing="0">
<tr>
<td colspan="3"><form id="form" name="form" method="post" action="sec.asp">
<table width="100%" border="1" cellpadding="0" cellspacing="0" class="thin">
<tr>
<td width="30%" align="right" valign="middle" class="STYLE2">查詢內容:</td>
<td align="left" valign="middle" class="STYLE2"><input name="nr" type="text" id="nr" /></td>
</tr>
<tr>
<td width="30%" align="right" valign="middle" class="STYLE2">日期:</td>
<td align="left" valign="middle" class="STYLE2"><input name="ksrq" type="text" id="ksrq" />

<input name="jsrq" type="text" id="jsrq" />
(請按2000-1-30這樣的格式輸入)</td>
</tr>
<tr>
<td colspan="2" align="center" valign="middle" class="STYLE2"><input type="submit" name="Submit" value="查 詢" /></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</body>
</html>

sec.asp:

<% '建立資料庫連接
set conn=server.createobject("adodb.connection")
connstr="driver={SQL Server};server=/輸入伺服器ip地址/; uid=/資料庫用戶名/;pwd=/資料庫密碼;database=sql的數據源名,也就是ODBC里建立的資料庫名/" '請把/……/改成正確的內容。
conn.open connstr
nr=request.Form("nr")
ksrq=request.Form("ksrq")
jsrq=request.Form("jsrq")
if nr<>"" and ksrq<>"" and jsrq<>"" then
set rs=server.createobject("adodb.recordset")
sql="select * from [表名] where 列標題="&nr&" and 日期列 (between #"&ksrq&"# and #"&jsrq&"#) order by id desc"
rs.open sql,conn,1,1
else
if nr<>"" and ksrq="" and jsrq="" then
set rs=server.createobject("adodb.recordset")
sql="select * from [表名] where 列標題="&nr&" order by id desc"
rs.open sql,conn,1,1
else
if nr="" and ksrq<>"" and jsrq<>"" then
set rs=server.createobject("adodb.recordset")
sql="select * from [表名] where 日期列 between #"&ksrq&"# and #"&jsrq&"# order by id desc"
rs.open sql,conn,1,1
else
msgbox "輸入條件不對,請點後退按鈕重新輸入。"
end if
end if
end if
%>

<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>無標題文檔</title>
<style type="text/css">
<!--
.thin { border-collapse: collapse;
}
.STYLE2 {font-size: 12px; color: #000000; }
-->
</style>
</head>

<body>
<table width="80%" border="1" align="center" cellpadding="0" cellspacing="0" class="thin">
<tr>
<td width="20%" height="20" align="center" valign="middle" bgcolor="#FFFFCC" class="STYLE2">查詢結果列1</td>
<td width="20%" height="20" align="center" valign="middle" bgcolor="#FFFFCC" class="STYLE2">查詢結果列2</td>
<td width="20%" height="20" align="center" valign="middle" bgcolor="#FFFFCC" class="STYLE2">查詢結果列3</td>
<td width="20%" height="20" align="center" valign="middle" bgcolor="#FFFFCC" class="STYLE2">查詢結果列4</td>
<td height="20" align="center" valign="middle" bgcolor="#FFFFCC" class="STYLE2">日期列</td>
</tr>
<%do while not rs.eof%>
<tr>

<td width="20%" align="center" valign="middle" bgcolor="#F0F0F0" class="STYLE2"><%=rs("顯示查詢結果列1")%></td>
<td width="20%" align="center" valign="middle" bgcolor="#F0F0F0" class="STYLE2"><%=rs("顯示查詢結果列2")%></td>
<td width="20%" align="center" valign="middle" bgcolor="#F0F0F0" class="STYLE2"><%=rs("顯示查詢結果列3")%></td>
<td width="20%" align="center" valign="middle" bgcolor="#F0F0F0" class="STYLE2"><%=rs("顯示查詢結果列4")%></td>
<td align="center" valign="middle" bgcolor="#F0F0F0" class="STYLE2"><%=rs("日期列")%></td>
</tr>
<%
rs.movenext
loop
rs.close
set rs=nothing
conn.close
set rs=nothing
%>
</table>
</body>
</html>

復制serch.asp保存為serch.asp
復制sec.asp保存為sec.asp,修改代碼,保存,然後就可以了.

『柒』 用asp調用資料庫中的數據,請幫忙

<table width="200" border="0" align="center" cellpadding="0" cellspacing="0">
<%
if anclassid="" then
set rsok=server.createobject("ADODB.recordset")
sqlok="select * from sort order by anclassidorder"
rsok.open sqlok,conn,1,1
do while not rsok.eof
%>
<tr height="25">
<td width="13%"> </td>
<td width="83%" style="border-bottom:1px solid #CCCCCC " align="center">
<b>【<a href="procts.asp?id=big&anclassid=<%=rsok("anclassid")%>"><%=rsok("anclassname")%></a>】</b></td>
<td width="4%"> </td>
</tr>
<%rsok.movenext
loop
rsok.close
set rsok=nothing
else%>
<tr height="25">
<td width="13%"> </td>
<td width="83%" style="border-bottom:1px solid #CCCCCC " align="center">
</td>
<td width="4%"> </td>
</tr>
<%end if%>
</table>
--------------------------
針對「在對應所需名稱或序數的集合中,未找到項目」的調試方法:
語句rsok.open sqlok,conn,1,1 沒有問題,追溯到上一關鍵語句
sqlok="select * from sort order by anclassidorder"
先精簡SQl語句
嘗試sqlok="select * from sort"看是否報錯,如果仍然報錯,看資料庫中表名sort是否有拼寫錯誤。
如果不報錯,查看sort表是否包含欄位anclassidorder
如果兩者都不是就發消息給我,我給你我的QQ,要快哦,等一下要是下班了今天就幫不到你了

『捌』 ASP.NET的資料庫怎麼調用

SqlConnection
conn
=
new
SqlConnection(GetConnectionString.conn());
SqlCommand
cmd
=
conn.CreateCommand();
cmd.CommandType
=
CommandType.StoredProcere;
//指定執行存儲過程操作
cmd.CommandText
=
"fangSTDEquGroup";
//存儲過程名稱
SqlDataAdapter
da
=
new
SqlDataAdapter(cmd);
//定義一個數據適配器
DataSet
DataSet2
=
new
DataSet();
//定義一個數據集
da.Fill(DataSet2);
//填充數據集
DataTable
dt
=
DataSet2.Tables[0];
//取數據集中的表進行操作
TreeView2.Nodes.Clear();
TreeNode
cc
=
new
TreeNode();
cc.Text
=
"設備";
cc.Value
=
"設備";
TreeView2.Nodes.Add(cc);
foreach
(DataRow
dr
in
dt.Rows)
{
TreeNode
tn
=
new
TreeNode();
tn.Text
=
dr["StrName"].ToString();
tn.Value
=
dr["IDCode"].ToString();
cc.ChildNodes
.Add(tn);
}
conn.Close();
提取數據集最好還是改成用自定義函數來調用,這樣寫你更容易看懂

『玖』 asp網頁關於acc資料庫調用的菜鳥問題

數據表不多合並嘛,表倒到一個MBD庫裡面,用一個conn.asp就可以 ,還有就是conn.asp 打開資料庫的鏈接地址是否正確,是相當路徑還是絕對路徑,相對路徑的話你看看,是不是多了../

鏈接對象名稱不要一樣
Set oConn = Server.CreateObject("ADODB.Connection")
Set Conn = Server.CreateObject("ADODB.Connection")

『拾』 asp調用資料庫

ACCESS資料庫的連接
<%
set conn=server.createobject("adodb.connection")
conn.open "driver={microsoft access driver (*.mdb)};dbq="&server.mappath("資料庫")
%>
第一句話定義了一個adodb資料庫連接組件,第二句連接你的資料庫。
<%
exec="select * from 資料庫表名"
set rs=server.createobject("adodb.recordset")
rs.open exec,conn,1,1
%>
這三句加在前面兩句的後面。
第一句:設置查詢資料庫的命令,select後面加的是欄位,如果都要查詢的話就用*,from後面再加上表的名字。
第二句:定義一個記錄集組件,所有搜索到的記錄都放在這裡面,
第三句:是打開這個記錄集,exec就是前面定義的查詢命令,conn就是前面定義的資料庫連接組件,後面參數「1,1」,這是讀取。
<%do while not rs.eof%>
...
<%
rs.movenext
loop
%>
<%=rs("欄位名")%>
用do循環,not rs.eof的意思是條件為沒有讀到記錄集的最後,rs.movenext的意思是顯示完一條轉到下面一條記錄。
主要用於顯示欄位變數。
例如:做一個讀取資料庫記錄的頁面
用access2000建立資料庫db1,建立表biao1,欄位:id(自動編號),name(文本),qq(數字),neirong(備注),time(時間、日期/默認值now())。
頁面代碼是:
<%
set conn=server.createobject("adodb.connection")
conn.open "driver={microsoft access driver (*.mdb)};dbq="&server.mappath("db1.mdb")
%>
<%
exec="select * from biao1 order by id desc"
set rs=server.createobject("adodb.recordset")
rs.open exec,conn,1,1
%>
<%do while not rs.eof%>
<%=rs("id")%><%=rs("name")%><%=rs("qq")%><%=rs("neirong")%><%=rs("time")%><br>
<%
rs.movenext
loop
%>

熱點內容
jsp輸出腳本 發布:2024-10-29 07:19:49 瀏覽:507
ps存儲不了怎麼辦 發布:2024-10-29 07:15:47 瀏覽:356
對數減法運演算法則 發布:2024-10-29 06:59:11 瀏覽:50
五萬多帝豪什麼配置 發布:2024-10-29 06:57:04 瀏覽:527
工藝員編程 發布:2024-10-29 06:31:06 瀏覽:113
大嘴腳本是什麼 發布:2024-10-29 06:20:59 瀏覽:205
電腦批量壓縮圖片軟體 發布:2024-10-29 06:14:39 瀏覽:720
php郵件內容 發布:2024-10-29 06:14:33 瀏覽:836
偽裝者緩存 發布:2024-10-29 06:12:19 瀏覽:787
原神怎麼調低手機配置 發布:2024-10-29 06:12:01 瀏覽:1001