av激情亚洲男人的天堂国语,日韩欧美精品一中文字幕,无码av一区二区三区无码,国产又色又爽又刺激的a片,国产又色又爽又刺激的a片

演示ADO.NET使用存儲(chǔ)過程獲取數(shù)據(jù)

ADO.NET經(jīng)過長(zhǎng)時(shí)間的發(fā)展,很多用戶都很了解ADO.NET了,這里我發(fā)表一下個(gè)人理解,和大家討論討論。代碼并不創(chuàng)建 Connection 對(duì)象或 Command 對(duì)象。事實(shí)上,沒有這些對(duì)象,ADO.NET 便無法工作,但它們是在后臺(tái)創(chuàng)建并使用的。實(shí)例化 SqlDataAdapter 的代碼行傳入 SQL 字符串(用于配置后臺(tái) Command 對(duì)象)和連接字符串(用于配置后臺(tái) Connection 對(duì)象)。

創(chuàng)新互聯(lián)建站-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價(jià)比武夷山網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式武夷山網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋武夷山地區(qū)。費(fèi)用合理售后完善,十余年實(shí)體公司更值得信賴。

我們可以將此代碼更改為使用顯式 Connection 和 Command 對(duì)象,以便稍稍遠(yuǎn)離演示軟件。在表單上再放置一個(gè)按鈕,并將以下代碼放到 Click 事件中。

 
 
  1. Dim sConnectionString As String = _ 
  2. "server=localhost;uid=sa;pwd=;database=Northwind"  
  3. Dim sSQL As String = "SELECT * FROM Products" 
  4.  
  5. Dim cnNorthwind As New SqlConnection(sConnectionString)  
  6. Dim cmdProducts As New SqlCommand(sSQL, cnNorthwind)  
  7.  
  8. Dim daGetProducts As New SqlDataAdapter(cmdProducts)  
  9. Dim dsProducts As New DataSet()  
  10. daGetProducts.Fill(dsProducts, "Products")  
  11. DataGrid1.DataSource = dsProducts.Tables("Products")  

#T#此代碼通過顯式創(chuàng)建 Connection 和 Command 對(duì)象,并將這些對(duì)象附加到 DataAdapter,說明了 DataAdapters 的常用性。通過在實(shí)例化 DataAdapter 時(shí)傳入 cmdProducts,DataAdapter 的 SelectCommand 將自動(dòng)設(shè)置。然后,可以立即使用 DataAdapter 訪問數(shù)據(jù)庫。此代碼的結(jié)果與前一示例中的結(jié)果相同。盡管它有點(diǎn)接近真實(shí)軟件,但由于數(shù)據(jù)訪問是通過 SQL 語句實(shí)現(xiàn)的,因此仍然屬于演示軟件。

ADO.NET使用簡(jiǎn)單存儲(chǔ)過程獲取數(shù)據(jù)

如何將此演示軟件更改為ADO.NET使用存儲(chǔ)過程?只需更改幾行代碼。在表單上再放置一個(gè)按鈕,并將以下代碼放到 Click 事件中:

 
 
  1. Dim sConnectionString As String = _ 
  2. "server=localhost;uid=sa;pwd=;database=Northwind"  
  3. Dim cnNorthwind As New SqlConnection(sConnectionString)  
  4. Dim cmdProducts As New _  
  5. SqlCommand("十件最貴的產(chǎn)品", cnNorthwind)  
  6. cmdProducts.CommandType = CommandType.StoredProcedure  
  7.  
  8. Dim daGetProducts As New SqlDataAdapter(cmdProducts)  
  9. Dim dsProducts As New DataSet()  
  10. daGetProducts.Fill(dsProducts, "Products")  
  11. DataGrid1.DataSource = dsProducts.Tables("Products")  

實(shí)例化 Command 對(duì)象時(shí),此代碼不使用 SQL 語句并替換為要ADO.NET使用的存儲(chǔ)過程名稱。此外,Command 對(duì)象的 CommandType 屬性必須設(shè)置為 StoredProcedure。此后的代碼與上一個(gè)示例非常相似,但它返回不同的數(shù)據(jù)。存儲(chǔ)過程查找十件最貴的產(chǎn)品,并只返回每個(gè)產(chǎn)品的名稱和價(jià)格。


網(wǎng)頁標(biāo)題:演示ADO.NET使用存儲(chǔ)過程獲取數(shù)據(jù)
網(wǎng)頁網(wǎng)址:http://uogjgqi.cn/article/cocgepg.html
掃二維碼與項(xiàng)目經(jīng)理溝通

我們?cè)谖⑿派?4小時(shí)期待你的聲音

解答本文疑問/技術(shù)咨詢/運(yùn)營(yíng)咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流