當前位置:首頁 » 操作系統 » asp從資料庫中讀取數據

asp從資料庫中讀取數據

發布時間: 2022-04-19 22:44:50

A. ASP讀取資料庫內容

這個還不容易啊. 你在資料庫裡面應該有信息的id 和 信息的 標題title吧. 首先調用資料庫, 就是我們說的標題列表. 如果是用表格布局的話 列表的代碼應該是這樣寫的 <% set rs = server.CreateObject("ADODB.Recordset") sql = "select * from 表名 where 條件" rs.open sql,conn,1,1 do while not rs.eof %> <tr> <td width="10"> </td> <td height="21">·<%=left(rs("title"),10)%> <td> <td width="10"> </td> </tr> <% rs.movenext loop rs.close set rs = nothing %> </table> 這樣文章的標題列表就顯示出來了 再加個連接到顯示文章的內容頁 就是在 <%=left(rs("title"),10)%>上加鏈接<a href = "內容頁顯示頁面?id = <%=rs("id")%>"> <%=left(rs("title"),10)%></a> 最後就是內容顯示頁 要顯示內容的話就是先讀取傳過來的id參數 <% set rs = server.CreateObject("ADODB.Recordset") sql = "select * from 表名 where id = '"&request("id")&"'" rs.open sql,conn,1,1 %> <tr> <td width="10"> </td> <td height="21"><%=rs("title")%> <td> <td width="10"><%=rs("content")%></td> </tr> <% rs.close set rs = nothing %> </table> 這樣就顯示出來了 追問: 列表頁的代碼:<!--#include file="conn.asp"--> <% exec="select * from PS" set rs=server.createobject("adodb.recordset") rs.open exec,conn,1,1 %> <div><%do while not rs.eof%> <a href = "show.asp?id = <%=rs("id")%>"><%=rs("psname")%></a> <% rs.movenext loop %> </div> 這是顯示內容頁的代碼: <!--#include file = "conn.asp" --> <% set rs=server.createobject("adodb.recordset") exec="select * from ps where id = '"&request("id")&"'" rs.open exec,conn,1,1 %> <table><tr><td><%=rs("pstitle")%></td></tr></table> 總是提示: Microsoft OLE DB Provider for ODBC Drivers (0x80040E21) ODBC 驅動程序不支持所需的屬性。 /myweb2/show.asp, 第 5 行 .... 麻煩你了. 回答: exec="select * from PS" set rs=server.createobject("adodb.recordset") 把兩行位置換下看 追問: 已經換過了.是一樣的.不知道是怎麼回事 回答: exec="select * from ps where id = '"&request("id")&"'" 改成 exec="select * from ps where id = "&request("id")&"" 追問: 也不行.還是同樣的錯誤.方便加QQ嗎 我的278455170

求採納

B. 關於ASP從資料庫讀取數據的問題 請進~~~~

set rs=Server.CreateObject("Adodb.Recordset")
創建一個記錄集對象rs(ADO資料庫組件中的Recordset對象),用它來獲存儲從資料庫中讀取出來的記錄,相當於臨時的數據容器。
sql="select top 30 * from ald_web where SMT_key=1 and SMT_key1=1 and SMT_key3=1 order by SMT_id desc"
定義一個字元串,這個字元串其實是一個SQL查詢字串
打開rs記錄集,其實就是向數據發出一個查詢,要執行查詢的資料庫是conn,查詢方法在sql這個字元串中定義,1,1是打開資料庫時的兩個參數,具體意思現在可以不用管,如果是讀取就用1,1 ,要是執行rs的update方法,就用1,3,記住就行了,以後再深究。

C. ASP從資料庫中讀取信息

Set cmd.ActiveConnection = connect connect這個是連接資料庫的一個對象,通過這個打開資料庫,然後讀取記錄。
不過,我不建議這樣寫。
sql2 = "SELECT * FROM users"
set rs = connect.Execute(sql2)
這樣就可以了,並且速度也很快。
Set cmd = Server.CreateObject("ADODB.Command")
這種方法也是讀取記錄的,不過這個適合調用存儲過程,用於sql資料庫。

D. 用ASP如何實現從資料庫中讀取數據並導出EXCEL

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

<%
on error resume next
Response.Buffer = True
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader "content-disposition", "inline; filename = 樓盤團購報名表"&cstr(date())&".xls"

dim rs,sql, sCount
sql = "SELECT * FROM [LouPan_Buy] ORDER BY ItemName ASC, ID DESC"
set rs=server.CreateObject("adodb.recordset")
rs.open sql,conn,1,1
sCount = rs.recordcount
%>

E. ASP從資料庫中讀取數據

select * from tablename where id in (select top 20 id from (select top 100020 id from tablename order by id asc) temptablename order by id desc) order by id desc
這個語句就是取100001 ~ 100020 之間的20條記錄。速度當然就是快,記住id是主鍵,弄清臨時表中的id排序。

F. asp中如何從資料庫中的一個表中讀取數據並存入另一個表

代碼是連在一起的么?建議你把變數定義成全局的,不要放在while循環裡面,如下:
string
bookid
=
「」;
while(res.next()){
bookid=res.getstring(1);

而且connection
第一次已經取了,也可以這樣定義了之後直接在下面進行使用,沒必要再寫一遍

G. asp中如何讀取sqlserver資料庫中的數據

<%
SETConn=Server.CreateObject("ADODB.Connection")
Dimi,j,Sql
Setrt=Server.CreateObject("ADODB.Recordset")
'Conn.Open"Server=IP地址;Provider=sqloledb;Database=庫名稱;UID=用戶名;PWD=密碼;"
Conn.Open"Server=192.168.1.1;Provider=sqloledb;Database=mysql;UID=sa;PWD=mysql;"
%>
<tablebordercolor="#808000"border="1"cellspacing="0"bgcolor="#EEEEEE">
<%'讀SqlServer庫中的表名:
Setrs=Conn.OpenSchema(20)
Whilenotrs.EOF
ifrs(3)="TABLE"then
'response.write(rs(2)&"<br>")'表的類型
'Response.Write("所在資料庫名:"&rs(0))
'Response.Write("所有者:"&rs(1))
'Response.Write("表名:"&rs(2)&"<br>")
%>
<tr>
<td><%=rs(2)%></td>
<%
'這樣,知道表名了,現在再來看看怎麼對表的欄位進行操作。假設:其中資料庫中有表:[admin]獲取該表的所有欄位名:
x="[admin]"
rt.open"select*from"&rs(2)&"where1<>1",conn,1,3
j=rt.Fields.count
Fori=0to(j-1)

'Response.Write("第"&i+1&"個欄位名:"&rt.Fields(i).Name&"<br><br>")
response.write("<td>"&rt(i).name)
Next
rt.close

endif
rs.MoveNext
Wend
%>

</table>

H. asp怎樣讀取資料庫的幾條數據

<%
Set Conn = server.CreateObject("ADODB.Connection")
ConnString = "provider=microsoft.jet.oledb.4.0;data source="
Conn.open ConnString & Server.MapPath("DataBase/Newsdskjfhs.mdb")
%>

<%
Set rs1 = Server.CreateObject("ADODB.Recordset")
rs1.open "select * from tType",conn,1,1
for i = 0 to rs1.RecordCount - 1
%>
<table width="100%" border="0" cellspacing="1">
<tr>
<td height="25" bgcolor="#00CCFF" class="f1"><%=rs1("TypeName")%><a href="More.asp?type=<%=rs1("typeid")%>" class="A">更多……</a></td>
</tr>
<tr>
<td height="117" valign="top">
<%
Set rs2 = Server.CreateObject("ADODB.Recordset")
Sql = "select top 8 * from tNews where NewsTypeID=" & rs1("TypeID") & " order by NewsDate desc"
rs2.open Sql,Conn,1,1
if rs2.eof and rs2.bof then
Response.Write("該版塊暫無新聞")
else
do while not rs2.eof
%> <a href="Show.asp?NewsID=<%=rs2("Newsid")%>" class="B"><%=rs2("Newstitle")%></a><span class="f2">[<%=rs2("Newsdate")%>]</span><br>
<%rs2.movenext
Loop
end if
%>
</td>
</tr>
</table>
<% rs1.movenext
next
%>
<%
Set conn = nothing
Set rs1 = nothing
Set rs2 = nothing
%>
你要是告訴我你的EMAIL ,我給你發到郵箱源碼(在學校做的,呵呵)

I. asp.net怎麼讀取資料庫中的數據。

標准做法是用DataAdapter填充一個DataTable

OleDbCommand b = new OleDbCommand();
b.Connection = a;
b.CommandText = "select [number] from gamelist where (game='"+cb1.Text+"')";

OleDbDataAdapter adpt = new OleDbDataAdapter (b);
DataTable dt = new DataTable();
adpt.Fill(dt);

int c=Convert.ToInt32(dt.Tables[0].Rows[0]["number"]);

熱點內容
搞笑解壓圖片大全 發布:2024-09-30 23:11:28 瀏覽:745
游戲源碼商 發布:2024-09-30 23:09:32 瀏覽:896
java物聯網 發布:2024-09-30 22:53:38 瀏覽:197
劍網3按鍵精靈腳本 發布:2024-09-30 22:45:38 瀏覽:940
存儲ssd緩存 發布:2024-09-30 22:45:34 瀏覽:690
為什麼電視裡面送銀行卡不給密碼 發布:2024-09-30 22:35:31 瀏覽:817
ftp電纜 發布:2024-09-30 22:34:56 瀏覽:337
python讀取數組 發布:2024-09-30 22:34:55 瀏覽:810
gl哪個配置好 發布:2024-09-30 22:22:46 瀏覽:415
多相機演算法 發布:2024-09-30 22:05:52 瀏覽:942