图1 ASP页面 |
| <%@ Language=VBScript %> <HTML> <HEAD> <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0"> <STYLE> BODY { font:arial } H1 { color:navy } </STYLE> </HEAD> <BODY> <DIV align=center> <H1>Authors</H1> <% ' ' Connecting to a database ' dim cn set cn = server.CreateObject("ADODB.Connection") cn.Open "Provider=sqloledb;" _ & "Data Source=(local);" _ & "Initial Catalog=pubs;" _ & "User ID=sa" ' Retrieving Data via the Recordset Object. dim rs set rs = server.CreateObject("ADODB.Recordset") rs.Open "select au_fname, au_lname, phone from authors order by au_lname",cn %> |
| <TABLE border='1'> <TR> <TH>First Name</TH> <TH>Last Name</TH> <TH>Phone</TH> </TR> <% do until rs.EOF Response.Write "<TR>" Response.Write "<TD>" & rs("au_fname") & "</TD>" Response.Write "<TD>" & rs("au_lname") & "</TD>" Response.Write "<TD>" & rs("phone") & "</TD>" Response.Write "</TR>" rs.MoveNext loop %> </TABLE> <!-- Footer --> <h5>Current as of <%Response.Write now%></h5> </DIV> </BODY> </HTML> |
图2 ASP页面显示结果 |
图3 ASP.NET页面 |
| <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.SqlClient" %> <HTML> <HEAD> <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0"> <STYLE> BODY { font:arial } H1 { color:navy } </STYLE> </HEAD> <BODY> <DIV align=center> <H1>Authors</H1> |
| < script language="VB" runat="server"> Sub Page_Load(Src As Object, E As EventArgs) Dim DS As DataSet Dim MyConnection As SQLConnection Dim MyCommand As SQLDataAdapter MyConnection = New SQLConnection("server=localhost;uid=sa;pwd=;database=pubs") MyCommand=New SQLDataAdapter("select au_fname as 'First Name', au_lname as 'Last Name',Phone from Authors",MyConnection) |
| DS = new DataSet() MyCommand.Fill(ds,"Authors") |
| grdAuthors.DataSource=ds.Tables("Authors").DefaultView |
| grdAuthors.DataBind() End Sub </script> |
| <asp:DataGrid runat=server id=grdAuthors/> <!-- Footer --> <h5>Current as of <%Response.Write (Now.ToString)%></h5> </DIV> </BODY> </HTML> |
图4 ASP.NET显示页面 |
| 共分1页 [1] |
关于网站 | 客服中心 | 服务条款 | 友情链接 | 广告联系 | 本站历程 | 网站导航
吉ICP备05000107号