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

asp從資料庫讀取數據

發布時間: 2023-08-22 08:31:21

1. asp.net怎麼讀取資料庫表中所有的信息

如果用的是sql Server 資料庫的話就用SQLDatasource對象連接資料庫,
如果用的是Access資料庫的話就用OLEDBDatasource對象連接資料庫,然後再用一個資料庫表的顯示空件GridView將前面所說的其中的一種對象作為數據源,顯示在此控制項上,就可以了。
總結一下,需要兩步:將資料庫信息作為連接對象的數據源,將這些連接對象的內容作為顯示控制項的數據源。類似一種傳遞吧。
這是我個人由所學知識對你疑問的解釋,希望對你的理解有所幫助!

2. 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 ,我給你發到郵箱源碼(在學校做的,呵呵)

3. asp.net如何提取資料庫中的值

Sqlserver資料庫可以採用:ADO.NET才獲取資料庫中的值:
public string GetPhoneByUserName(string UserName)
{
SqlConnection conn = new SqlConnection("Server=.;database=資料庫名;uid=sa;pwd=***");
conn.Open();
SqlCommand comm=new SqlCommand(conn,"select phonenumber from 表名 where UserName=『"+UserName+"'");

return comm.ExcuteReader();
}
然後在頁面後台代碼中:this.TextBox.Text=GetPhoneByUserName(Session["UserName"].ToString());

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

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

5. 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>

熱點內容
safemon是什麼文件夾 發布:2025-03-09 07:47:03 瀏覽:818
ipa反編譯源碼 發布:2025-03-09 07:41:06 瀏覽:295
電腦xp密碼忘了怎麼辦 發布:2025-03-09 07:38:18 瀏覽:827
聯想雲控制台只能一個伺服器嗎 發布:2025-03-09 07:38:16 瀏覽:584
大學編程系 發布:2025-03-09 07:34:13 瀏覽:775
把伺服器ip地址轉換成域名 發布:2025-03-09 07:32:56 瀏覽:449
pt和pe代表什麼配置 發布:2025-03-09 07:32:21 瀏覽:579
怎麼配置生長素的濃度 發布:2025-03-09 07:26:35 瀏覽:16
安卓鎖屏照的照片保存在哪裡 發布:2025-03-09 07:11:17 瀏覽:245
紅米找回賬號密碼怎麼辦 發布:2025-03-09 07:05:46 瀏覽:484