从【工具箱】中的【Windows窗体组件】选项卡中往Form 窗体中拖入下列组件 并执行相应的操作:
一个DataGrid组件
二个Button组件 分别是Button 至Button 并在这二个Button组件拖入Form 的设计窗体后 分别双击它们 则系统会在Form vb文件分别产生这二个组件的Click事件对应的处理代码
按照表 所示调整窗体中各组件属性的数值
组件类型 组件名称 属性 设置结果 Form Form Text 测试Web Service Form MaximizeBox False Form FormBorderStyle FixedSingle Button Button Text 绑定 Button FlatStyle Flat Button Text 修改 Button FlatStyle Flat
表 :【TestWebService】项目中组件的主要属性及其对应数值
在调整完组件属性值后 再按照图 所示调整组件的位置和排列顺序:
图 :【TestWebService】项目中组件排列位置和顺序
把Visual Studio Net的当前窗口切换到Form vb的代码编辑窗口 并用下列代码替换Form vb中的Button 的Click事件对应的处理代码 下列代码功能是使用Web Service中提供的 Binding 服务对DataGrid组件实现数据绑定:
Private Sub Button _Click ( ByVal sender As System Object ByVal e As System EventArgs ) Handles Button Click Dim MyService As New localhost Service ( ) DataGrid DataSource = MyService Binding ( ) DataGrid DataMember = Cust End Sub
用下列代码替换Form vb中的Button 的Click事件对应的处理代码 下列代码功能是使用Web Service中提供的 Update 服务实现通过DataGrid来修改数据库数据:
Private Sub Button _Click ( ByVal sender As System Object ByVal e As System EventArgs ) Handles Button Click Dim MyService As New localhost Service ( ) Dim ds As DataSet = DataGrid DataSource Dim dsChanges As DataSet = ds GetChanges ( ) If Not ( dsChanges Is Nothing ) Thends Merge ( MyService Update ( dsChanges ) True ) End IfEnd Sub
至此 【TestWebService】项目的全部工作就完成了 调用Web Service是不是很简单 此时单击快捷键F 运行程序后 单击程序中的【绑定】按钮就会对程序中的DataGrid组件实现数据绑定 单击程序中的【修改】按钮 则程序会根据DataGrid中的内容来更新数据库 图 就是【TestWebService】的运行界面:
图 :【TestWebService】的运行界面
Form vb的代码清单如下:
Public Class Form Inherits System Windows Forms Form#Region Windows 窗体设计器生成的代码 Public Sub New ( ) MyBase New ( )该调用是 Windows 窗体设计器所必需的InitializeComponent ( )在 InitializeComponent ( ) 调用之后添加任何初始化End Sub 窗体重写处置以清理组件列表 Protected Overloads Overrides Sub Dispose ( ByVal disposing As Boolean ) If disposing ThenIf Not ( ponents Is Nothing ) Then ponents Dispose ( )End If End If MyBase Dispose ( disposing )End Sub Windows 窗体设计器所必需的Private ponents As System ComponentModel IContainer注意 以下过程是 Windows 窗体设计器所必需的可以使用 Windows 窗体设计器修改此过程不要使用代码编辑器修改它Friend WithEvents Button As System Windows Forms Button Friend WithEvents Button As System Windows Forms Button Friend WithEvents DataGrid As System Windows Forms DataGrid System Diagnostics DebuggerStepThrough ( )Private Sub InitializeComponent ( ) Me Button = New System Windows Forms Button ( ) Me Button = New System Windows Forms Button ( ) Me DataGrid = New System Windows Forms DataGrid ( ) CType ( Me DataGrid System ComponentModel ISupportInitialize ) BeginInit ( ) Me SuspendLayout ( ) Me Button FlatStyle = System Windows Forms FlatStyle Flat Me Button Location = New System Drawing Point ( ) Me Button Name = ButtonMe Button Size = New System Drawing Size ( ) Me Button TabIndex =Me Button Text = 绑定Me Button FlatStyle = System Windows Forms FlatStyle Flat Me Button Location = New System Drawing Point ( ) Me Button Name = ButtonMe Button Size = New System Drawing Size ( ) Me Button TabIndex =Me Button Text = 修改Me DataGrid DataMember =Me DataGrid Dock = System Windows Forms DockStyle Top Me DataGrid HeaderForeColor = System Drawing SystemColors ControlText Me DataGrid Name = DataGridMe DataGrid Size = New System Drawing Size ( ) Me DataGrid TabIndex =Me AutoScaleBaseSize = New System Drawing Size ( ) Me ClientSize = New System Drawing Size ( ) Me Controls AddRange ( New System Windows Forms Control ( ) {Me DataGrid Me Button Me Button } ) Me Name = FormMe Text = 测试Web ServiceCType ( Me DataGrid System ComponentModel ISupportInitialize ) EndInit ( ) Me ResumeLayout ( False )End Sub#End RegionPrivate Sub Button _Click ( ByVal sender As System Object ByVal e As System EventArgs ) Handles Button Click Dim MyService As New localhost Service ( ) DataGrid DataSource = MyService Binding ( ) DataGrid DataMember = Cust End SubPrivate Sub Button _Click ( ByVal sender As System Object ByVal e As System EventArgs ) Handles Button Click Dim MyService As New localhost Service ( ) Dim ds As DataSet = DataGrid DataSource Dim dsChanges As DataSet = ds GetChanges ( ) If Not ( dsChanges Is Nothing ) Thends Merge ( MyService Update ( dsChanges ) True ) End IfEnd SubEnd Class
推荐阅读
- 如何把3个文件合成pdf,三个文件合成一个pdf
- 13号唱片是什么视频,13号唱片和11号唱片
- chatgpt创始人姐妹,chainplus创始人
- java满意度调查代码 java调查问卷
- 戴尔笔记本显卡怎么调,戴尔笔记本调显存
- 学html5哪好,直接学html5
- b站造梦无双直播,造梦无双手游直播
- linux中日志打印命令 linux打印日志到指定文件方法
- 手机怎么下载文件传到u盘,手机如何直接下载文件到u盘