六月婷婷综合激情-六月婷婷综合-六月婷婷在线观看-六月婷婷在线-亚洲黄色在线网站-亚洲黄色在线观看网站

明輝手游網中心:是一個免費提供流行視頻軟件教程、在線學習分享的學習平臺!

asp向asp.net應用程序的轉變過程

[摘要]下面示例中的第一個代碼塊對于某類 ASP 應用程序是很典型的,該類應用程序使用 ADO 讀取和操作從單個 SQL 查詢返回的記錄集。它使用 ADO Recordset 對象讀取從用 Microsoft Access 提供的 Northwind 示例數據庫返回的數據記錄。這些代碼將包含在具有 .as...

      下面示例中的第一個代碼塊對于某類 ASP 應用程序是很典型的,該類應用程序使用 ADO 讀取和操作從單個 SQL 查詢返回的記錄集。它使用 ADO Recordset 對象讀取從用 Microsoft Access 提供的 Northwind 示例數據庫返回的數據記錄。這些代碼將包含在具有 .asp 文件擴展名的文件中。
[Visual Basic]
<%@LANGUAGE=VBSCRIPT%>
<!
This ASP example uses ADO to read records from a database and print two
fields from all returned records to an ASP page. Connection to the Northwind database is through an ODBC system data source (DSN.
>
<html>
<body>
<%
   dim ADOconn, ADOrs, sqlstr
   sqlstr="SELECT * FROM Employees;"
   set ADOconn = Server.CreateObject("ADODB.Connection")
   ADOconn.Open "DSN = Test"
   set ADOrs = ADOconn.execute(sqlstr)
   if ADOrs.BOF and ADOrs.EOF then ' Query didn't return any records.
      Response.Write("No Records.")
   else
      ADOrs.MoveFirst
      Do While Not ADOrs.EOF
         Response.Write(ADOrs("FirstName") & " " _
            & ADOrs("LastName") & "<br>")
         ADOrs.MoveNext
      Loop
      Response.Write("<p>End of data.")  
   end if
   ADOrs.close
   set ADOrs = nothing
%>
</body>
</html>

 

下面的示例闡釋將前面示例轉換為 ASP.NET 應用程序所需的最低程度的更改。為了符合新的 Visual Basic 語法,大多數的更改都是必要的。此文件可以用 .aspx 文件擴展名重命名,并且將與 ASP.NET 一起運行。修改后的代碼行以粗體顯示。注意,在第一行上添加了具有 aspcompat=true 屬性的 <%@ Page > 指令。


[Visual Basic]
<%@Page aspcompat=true Language = VB%>
<!
This example uses ADO to read records from a database and print two
fields from all records in the database to an ASP.NET page.
The database is located on the server and connection is through an ODBC system data source (DSN.
>
<html>
<body>
<%
   dim objConn, rs, sqlstr
   sqlstr="SELECT * FROM Employees;"
   objConn = Server.CreateObject("ADODB.Connection") ' Set removed.
   objConn.Open("DSN=TEST") ' Parentheses added.
   rs = objConn.execute(sqlstr) ' Set statement removed.
   Response.Write("<p>ADO Test</p>")

   if rs.BOF and rs.EOF then ' Query didn't return any records.
      Response.Write("No Records")
   else
      rs.MoveFirst
      Do While Not rs.EOF
         ' Specify Value property.
         Response.Write(rs("FirstName").Value _
            & " " & rs("LastName").Value & "<br>")
         rs.MoveNext
      Loop
      Response.Write("<p>End of data")
   end if
   rs.close
   rs = nothing ' Set statement removed.
%>

 


下一個示例是一個 ASP.NET 應用程序,該程序使用 ADO.NET 從與前面示例相同的 Northwind 數據庫讀取記錄。這些代碼生成的輸出等效于前面示例的輸出,而且已被修改以符合 ASP.NET 代碼塊約定。

該示例創建一個 ADO.NET DataSet 對象,在此情況下此對象包含一個數據表,而該數據表的使用方式與 ADO 記錄集的使用方式幾乎相同。請注意,數據集可以由一個或多個構成內存駐留數據庫的 DataTables、DataRelations 和 Constraints 的集合組成,因此 ADO.NET 數據集比 ADO 記錄集靈活得多。

為了使用 ADO.NET,需要導入 System.Data 和 System.Data.OleDb 命名空間。如果數據源是 SQL Server 數據庫,則導入 System.Data.SqlClient 命名空間而不是 System.Data.OleDb。有關使用 ADO 和 SQL .NET 數據提供程序的連接對象的詳細信息,請參見管理連接。

[Visual Basic]
<%@Import Namespace="System.Data"%>
<%@Import Namespace="System.Data.OleDb"%>
<!
This example uses ADO.NET to read records from a database and print two
fields from all returned records to an ASP.NET page. The database
is located on the local server.
>
<html>
<Script Language=VB Runat=Server>
   Sub Page_Load(Sender As Object, e As EventArgs)
      Dim MyConnection As OleDbConnection
      Dim MyCommand As OleDbDataAdapter
      dim MyDataset As DataSet
      dim MyTable As DataTable
      dim loop1, numrows As Integer
      dim sqlstr As String
     
      sqlstr = "SELECT * FROM Employees;"
     
      ' Create a connection to the data source.
      MyConnection = New OleDbConnection("Provider=SQLOLEDB;" _
         & "server=localhost;"Integrated Security=SSPI;" _
         & "Initial Catalog=Northwind")

      ' Create a Command object with the SQL statement.
      MyCommand = New OleDbDataAdapter(sqlstr, MyConnection)

      ' Fill a DataSet with data returned from the database.
      MyDataset = New DataSet
      MyCommand.Fill(MyDataset)
     
      ' Create a new DataTable object and assign to it
      ' the new table in the Tables collection.
      MyTable = New DataTable
      MyTable = MyDataset.Tables(0)
      ' Find how many rows are in the Rows collection
      ' of the new DataTable object.
      numrows = MyTable.Rows.Count
       If numrows = 0 then
         Response.Write("<p>No records.</p>")
      Else
         Response.Write("<p>" & Cstr(numrows) & " records found.</p>")
         For loop1 = 0 To numrows - 1
            ' Print the values of the two columns in the Columns
            ' collection for each row.
            Response.Write(MyTable.Rows(loop1).Item("FirstName") _
               & " " & MyTable.Rows(loop1).Item("LastName") & "<br>")
         Next loop1
      End If
      Response.Write("<p>End of data.</p>")  
   End Sub
</Script>
</html>

在數據庫查詢(甚至是多表聯接查詢)返回單個記錄集的情況下,可以通過與使用 ADO 記錄集的方式幾乎相同的方式使用單個 DataTable(在此示例中為 MyTable)。

參考《NET  FRAMEWORK SDK文擋》




主站蜘蛛池模板: 亚洲入口 | 日韩成人毛片高清视频免费看 | 窝窝午夜色视频国产精品东北 | 中文字幕高清免费不卡视频 | 日本特黄a级高清免费酷网 日本特黄aaaaaaa大片 | 最新版天堂中文在线官网 | 一二三四免费观看高清观看在线 | 青青青免费观看在线视频网站 | 日韩理论片在线观看电视 | 亚洲欧美日韩精品一区 | 中文字幕亚洲无线码在一区 | 亚洲一级毛片 | 欧日韩不卡在线视频 | 日韩一级片免费在线观看 | 香蕉漫画基地成人 | 天天躁日日躁狠狠躁一级毛片 | 日本a在线视频 | 自拍亚洲欧美 | 日本欧美一区二区三区 | 欧美亚洲另类图片 | 四虎伊人| 天天操天天擦 | 日韩有码在线观看 | 亚洲第一欧美 | 日韩视频在线免费观看 | 日本欧美高清全视频 | 羞羞色在线观看 | 青青草国产免费久久久下载 | 一级黄色片免费的 | 亚洲免费天堂 | 日本一区二区在线播放 | 日本四虎影院 | 亚洲成人看片 | 午夜小片 | 最新欧美伦禁片在线观看 | 伊人久热这里只有精品视频99 | 午夜a爱 | 亚洲欧洲一区二区三区在线 | 特黄特色的免费大片看看 | 中国性欧美 | 日韩成片|