成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

VB.NET三層數據結構構建方式分析

開發 后端
VB.NET三層數據結構包括表示層;業務層以及數據層這三方面。下面我們將會針對這三層的創建步驟進行一個介紹,增加大家對此的理解程度。

VB.NET的編寫方式和其他語言相比有許多不同之處,比如在構建三層架構方面。我們就可以通過本文介紹的內容對此進行一個詳細的解讀。我們主要介紹的是VB.NET三層數據結構的實現,以及將介紹如何創建一個Web Service服務。#t#

該結構分三個層次:表示層、業務層、數據層。

數據層:代表物理數據庫。

業務層:負責數據層與表示層之間的數據傳輸。

表示層:應用程序的客戶端,它通過業務層來訪問數據庫。

表示層所操作的是駐留在內存中的本地數據,當需要更新數據庫數據時,要通過業務層提供的更新方法實現。這樣可以大大提高應用程序的性能,而且,什么時候更新數據完全由你決定,提高了編程的靈活性。

VB.NET三層數據結構實例:

這里我們具體做一個實例來看看如何用VB.NET三層數據結構的應用程序。

數據庫:我們選擇SQL SERVER 的NorthWind數據庫。

業務層:我們創建一個WebService作為中間層。(需要安裝IIS服務)

表示層:我們寫一個Windows Form

第一步:創建WebService.

VB.NET三層數據結構具體步驟如下:

1. 新建一個項目,選擇ASP.NET Web服務,命名為:“WebService For 業務層”。

2. 添加兩個Sql DataAdapter,一個為Customer_da,它指向NorthWind數據庫的Customers表,另一個為Order_da,指向Northwind數據庫的Orders表。

3. 然后生成一個Typed DataSet(選擇“數據”菜單的“生成數據集”),命名為:Super_ds.

4. 數據庫連接已經完成,下一步我們將考慮它與表示層之間的通信,這里我們定義兩個方法。一個為:Get_DataSet,它返回一個Super_ds類型的數據集,另一個為:Update_DataSet,它負責更新數據庫數據, 方法代碼如下:

  1. < WebMethod()> Public 
    Function Get_Dataset() 
    As super_ds  
  2. customer_da.Fill
    (Super_ds1.Customers)  
  3. order_da.Fill(Super_ds1.Orders)  
  4. Return Super_ds1  
  5. End Function  
  6. < WebMethod()> Public 
    Sub Update_Dataset()  
  7. Super_ds1.AcceptChanges()  
  8. End Sub 

你可以運行測試一下你建立的這個WebService.它將提供兩個方法。返回的DataSet是以XML表示的。

業務層的完整代碼如下:

  1. Imports System.Web.Services  
  2. Public Class Service1  
  3. Inherits System.Web.Services
    .WebService  
  4. ‘Web Services Designer 
    Generated Code……。  
  5. < WebMethod()> Public Function 
    Get_Dataset() As super_ds  
  6. customer_da.Fill(Super_ds1.Customers)  
  7. order_da.Fill(Super_ds1.Orders)  
  8. Return Super_ds1  
  9. End Function  
  10. < WebMethod()> Public Sub 
    Update_Dataset()  
  11. Super_ds1.AcceptChanges()  
  12. End Sub  
  13. ' WEB SERVICE EXAMPLE  
  14. ' The HelloWorld() example service 
    returns the string Hello World.  
  15. ' To build, uncomment the following
     lines then save and build the project.  
  16. ' To test this web service, ensure 
    that the .asmx file is the start page  
  17. ' and press F5.  
  18. '  
  19. '< WebMethod()> Public Function
     HelloWorld() As String  
  20. HelloWorld = "Hello World" 
  21. ' End Function  
  22. End Class 

VB.NET三層數據結構之創建表示層

具體步驟如下:

1. 新建一個Windows應用程序,命名為:“Windows Form For 表示層”。

2. 在窗體上添加一個DataGrid,一個Button,Button1的text為“Load”,作用是:從業務層讀取數據。

3. 在解決方案窗體中添加Web 引用,將我們自己建立的Web Service for 業務層引入到當前項目中。

4. 向Button1的Click事件添加如下代碼:

  1. Dim Customer_Ds As New 
    localhost.super_ds()  
  2. Dim ser1 As New local
    host.Service1()  
  3. Customer_Ds.Merge
    (ser1.Get_Dataset)  
  4. DataGrid1.DataSource 
    Customer_Ds 

這里我們調用了Web Service的Get_DataSet函數,Update_DataSet方法的調用與此完全相同。

#p#

表示層的完整代碼如下:

  1. Imports Data_Access_表示層  
  2. Public Class Form1  
  3. Inherits System.Windows.Forms.Form  
  4. #Region " Windows Form Designer 
    generated code "  
  5. Public Sub New()  
  6. MyBase.New()  
  7. 'This call is required by the 
    Windows Form Designer.  
  8. InitializeComponent()  
  9. 'Add any initialization after the 
    InitializeComponent() call  
  10. End Sub  
  11. 'Form overrides dispose to clean 
    up the component list.  
  12. Protected Overloads Overrides Sub 
    Dispose(ByVal disposing As Boolean)  
  13. If disposing Then  
  14. If Not (components Is Nothing) Then  
  15. components.Dispose()  
  16. End If  
  17. End If  
  18. MyBase.Dispose(disposing)  
  19. End Sub  
  20. Friend WithEvents Button1 As 
    System.Windows.Forms.Button  
  21. Friend WithEvents Button2 As 
    System.Windows.Forms.Button  
  22. Friend WithEvents Button3 As 
    System.Windows.Forms.Button  
  23. Friend WithEvents Client_DataSet 
    As Data_Access_表示層。localhost.super_ds  
  24. Friend WithEvents DataGrid1 As 
    System.Windows.Forms.DataGrid  
  25. 'Required by the Windows Form Designer  
  26. Private components As System.
    ComponentModel.Container  
  27. 'NOTE: The following procedure is 
    required by the Windows Form Designer  
  28. 'It can be modified using the 
    Windows Form Designer.  
  29. 'Do not modify it using the code editor.  
  30. < System.Diagnostics.Debugger
    StepThrough
    ()> Private Sub 
    InitializeComponent()  
  31. Me.Button1 = New System.
    Windows.Forms.Button()  
  32. Me.Button2 = New System.
    Windows.Forms.Button()  
  33. Me.Button3 = New System.
    Windows.Forms.Button()  
  34. Me.Client_DataSet = New 
    Data_Access_表示層。localhost
    .super_ds()  
  35. Me.DataGrid1 = New System.Windows.
    Forms.DataGrid()  
  36. CType(Me.Client_DataSet, System
    .ComponentModel.ISupportInitialize)。
    BeginInit()  
  37. CType(Me.DataGrid1, System.
    ComponentModel.ISupportInitialize)。
    BeginInit()  
  38. Me.SuspendLayout()  
  39. '  
  40. 'Button1  
  41. '  
  42. Me.Button1.Location = New System.
    Drawing.Point(88, 360)  
  43. Me.Button1.Name = "Button1" 
  44. Me.Button1.TabIndex = 0 
  45. Me.Button1.Text = "load" 
  46. '  
  47. 'Button2  
  48. '  
  49. Me.Button2.Location = New System.
    Drawing.Point(232, 360)  
  50. Me.Button2.Name = "Button2" 
  51. Me.Button2.TabIndex = 1 
  52. Me.Button2.Text = "update" 
  53. '  
  54. 'Button3  
  55. '  
  56. Me.Button3.Location = New System
    .Drawing.Point(376, 360)  
  57. Me.Button3.Name = "Button3" 
  58. Me.Button3.TabIndex = 2 
  59. Me.Button3.Text = "clear" 
  60. '  
  61. 'Client_DataSet  
  62. '  
  63. Me.Client_DataSet.DataSetName = 
    "Client_DataSet" 
  64. Me.Client_DataSet.Locale = New
     System.Globalization.CultureInfo("zh-CN")  
  65. Me.Client_DataSet.Namespace = 
    "http://www.tempuri.org/CustomerDs.xsd" 
  66. '  
  67. 'DataGrid1  
  68. '  
  69. Me.DataGrid1.DataMember = "" 
  70. Me.DataGrid1.Location = New 
    System.Drawing.Point(40, 56)  
  71. Me.DataGrid1.Name = "DataGrid1" 
  72. Me.DataGrid1.Size = New System.
    Drawing.Size(480, 264)  
  73. Me.DataGrid1.TabIndex = 3 
  74. '  
  75. 'Form1  
  76. '  
  77. Me.AutoScaleBaseSize = New 
    System.Drawing.Size(6, 14)  
  78. Me.ClientSize = New System.
    Drawing.Size(568, 429)  
  79. Me.Controls.AddRange(New 
    System.Windows.Forms.Control() 
    {Me.DataGrid1, Me.Button3, 
    Me.Button2, Me.Button1})  
  80. Me.Name = "Form1" 
  81. Me.Text = "Form1" 
  82. CType(Me.Client_DataSet, 
    System.ComponentModel.
    ISupportInitialize)。EndInit()  
  83. CType(Me.DataGrid1, System.
    ComponentModel.ISupportInitialize)。EndInit()  
  84. Me.ResumeLayout(False)  
  85. End Sub  
  86. #End Region  
  87. Private Sub Button1_Click(ByVal 
    sender As System.Object, ByVal e 
    As System.EventArgs) Handles Button1.Click  
  88. Dim Customer_Ds As New localhost.super_ds()  
  89. Dim ser1 As New localhost.Service1()  
  90. Customer_Ds.Merge(ser1.Get_Dataset)  
  91. DataGrid1.DataSource = Customer_Ds 
  92. End Sub  
  93. End Class 

總結:可見,VB.NET三層數據結構中的表示層窗體上完全沒有數據庫連接控件,它與數據庫的連接任務是通過業務層來完成的,這樣,程序的結構更加清晰,當然業務層的實現也可以用其他方法,比如:寫一個自己的類來完成與數據庫的數據傳輸。

責任編輯:曹凱 來源: 中國IT實驗室
相關推薦

2009-10-28 14:34:44

VB.NET Tree

2010-01-12 18:12:58

VB.NET事件

2014-06-05 11:15:21

eBay大數據

2009-10-28 10:04:53

VB.NET XmlW

2009-11-02 17:12:01

VB和VB.NET

2010-01-22 10:41:33

VB.NET聲明結構

2009-11-10 17:31:38

VB.NET注冊表

2009-11-04 10:54:53

VB.NET MOVE

2009-11-04 09:32:12

VB.NET Auto

2009-10-14 15:20:21

VB.NET窗體指針

2009-10-27 18:06:41

VB.NET開發控件

2009-10-12 13:11:48

VB.NET使用線程

2009-10-13 09:24:57

VB.NET Dock

2009-10-15 10:57:16

VB.NET Text

2009-10-29 15:16:02

VB.NET文件傳送

2010-01-12 14:02:14

VB.NET數據實體層

2009-10-14 14:19:00

VB.NET創建表示層

2010-01-14 15:15:22

VB.NET數據行處理

2010-01-07 15:49:10

VB.NET DoLoop

2010-01-12 17:49:03

VB.NET鍵盤輸入
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 成人国产午夜在线观看 | aaa精品 | 嫩草视频在线免费观看 | 欧美成人猛片aaaaaaa | 成人黄色av网址 | 99热精品国产 | 一级免费视频 | 一区二区三区四区免费在线观看 | 国产a视频| 欧美视频 亚洲视频 | 久久久久国产 | 色欧美综合 | 日韩国产一区二区 | 九九综合九九 | 欧美jizzhd精品欧美巨大免费 | www.日韩av.com | 国产一区二区久久 | 国产一区二区三区在线 | 欧美日韩精品影院 | 国产精品国产三级国产aⅴ入口 | 涩色视频在线观看 | 日韩中文字幕在线视频观看 | 91精品国产91久久久久久最新 | 国产视频中文字幕 | 国产精品69毛片高清亚洲 | 亚洲欧美一区二区三区情侣bbw | 夜夜操天天操 | 一区二区视屏 | 超碰在线网站 | 麻豆天堂 | 五月婷婷激情网 | 欧美在线视频不卡 | 国产精品美女久久久久aⅴ国产馆 | 中文字幕一区在线观看视频 | 精品久久久一区二区 | 国产小u女发育末成年 | 国产一级一级毛片 | 日韩在线视频网址 | 超碰免费在线观看 | 四虎影院免费在线播放 | 色婷婷久久久久swag精品 |