学院首页>网络编程>ASP>两种没有使用绑定的数据显示

两种没有使用绑定的数据显示

作者:豆腐技术站 来源:http://www.asp888.net 添加时间:2006-5-21 10:26:55
 不用DATAGRID,这里用了DATAREADER,和DATAROW来取得数据库的数据.这一点ASP.NET做得很好,既有比较简单的数据绑定方法,又允许这样的相对麻烦一些,但更为灵活的方法. 
/*
豆腐制作 都是精品

如转载 请保留版权信息 。
*/

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SQL" %>
<html>
<script language="VB" runat="server">

Dim dsCustomer as DataSet
Dim CustomersDSCommand as SQLDataSetCommand
Protected Sub Page_Load(Src as object, E as EventArgs )
'读出数据的第一种方法 
Dim myConnection as SQLConnection
Dim dtReader AS SQLDataReader
myConnection = new SQLConnection("server=localhost;uid=sa;pwd=;database=northwind")
CustomersDSCommand = new SQLDataSetCommand("SELECT * FROM customers", myConnection)
dsCustomer = new DataSet()
CustomersDSCommand.FillDataSet(dsCustomer, "Customers")
Dim Customer as DataRow
For Each Customer In dsCustomer.Tables("Customers").Rows
Response.Write(Customer("CustomerId").ToString() + "<BR>" )
Next
End Sub
Sub displaydata()
'读出数据的第二种方法
Dim dtReader AS SQLDataReader
Dim sqlcmd AS SQLCommand
Dim sqlserver AS String
Dim sql AS String
sqlserver = "server=localhost;uid=sa;password=;database=northwind"
SQL = "Select * from customers"
sqlcmd = New SQLCommand(sql,sqlserver)
sqlcmd.ActiveConnection.Open()
sqlcmd.execute(dtreader)
Response.write("再进行数据库open后,我们来显示这个Table 的某一个字段的数值")
While dtReader.Read()
response.write (dtreader.Item("CustomerId") & "
")
End While
End Sub
</script>

<body>
</body>
</html>
站内搜索