溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

VB.NET中怎么實現數據綁定

發布時間:2021-08-06 15:31:35 來源:億速云 閱讀:252 作者:Leah 欄目:編程語言

本篇文章給大家分享的是有關VB.NET中怎么實現數據綁定,小編覺得挺實用的,因此分享給大家學習,希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。

TextBox組件通過下列語句就可以把已經得到的數據集"myDataSet"中的"books.bookid"字段值綁定到TextBox1的"Text"屬性上:TextBox1.DataBindings.Add ( New Binding ( "Text" , Me.myDataSet , "books.bookid" ) ) 了解了這二點,就不難實現對TextBox組件的數據綁定了。下面是VB.NET實現數據綁定的源程序代碼:

Imports System.Drawing  Imports System.Windows.Forms  Imports System.ComponentModel  Imports System  Imports System.Data.OleDb  Imports System.Data   Public Class Form1  Inherits Form   Private WithEvents Button1 As Button  Private TextBox1 As TextBox  Private myDataSet As DataSet  Private components As System.ComponentModel.Container   Public Sub New ( )  MyBase.New()  GetConnected ( )  InitializeComponent ( )  End Sub  '清除在程序中使用過的資源  Protected Overloads Overrides Sub Dispose ( ByVal disposing As Boolean )  If disposing Then  If Not ( components Is Nothing ) Then  components.Dispose ( )  End If  End If  MyBase.Dispose ( disposing )  End Sub  '打開數據表,返回數據集  public Sub GetConnected ( )  '創建一個 OleDbConnection  Dim strCon As String = " Provider = Microsoft.Jet.OLEDB.4.0; Data Source = ..\sample.mdb" Dim myConn As OleDbConnection = new OleDbConnection ( )  myConn.ConnectionString = strCon  Dim strCom As string = " SELECT * FROM books " '創建一個 DataSet  myDataSet = new DataSet( )   myConn.Open ( )  '用 OleDbDataAdapter 得到一個數據集  Dim myCommand As OleDbDataAdapter = new OleDbDataAdapter ( strCom , myConn )  '把Dataset綁定books數據表  myCommand.Fill ( myDataSet , "books" )  '關閉此OleDbConnection  myConn.Close ( )   End Sub  '初始化窗體中的組件  Private Sub InitializeComponent ( )  Me.Text = "對TextBox組件實現數據綁定!" Me.Width = 400 Me.Height = 300  Button1 = New Button ( )  TextBox1 = New TextBox ( )   Button1.Left = 200 Button1.Top = 200 Button1.Width = 100 Button1.Height = 40 Button1.TabIndex = 0 Button1.Text = "數據綁定"  TextBox1.Left = 200 TextBox1.Top = 30 TextBox1.Width = 150 TextBox1.Height = 40  Me.Controls.Add ( Button1 )  Me.Controls.Add ( TextBox1 )   End Sub   Private Sub Button1_Click ( ByVal sender As Object , _  ByVal e As System.EventArgs ) Handles Button1.Click  TextBox1.DataBindings.Add ( New Binding ( "Text" , Me.myDataSet , "books.bookid" ) )  End Sub  End Class   Module Module1  Sub Main ( )  Application.Run ( new Form1 ( ) )  End sub  End Module

以上就是VB.NET中怎么實現數據綁定,小編相信有部分知識點可能是我們日常工作會見到或用到的。希望你能通過這篇文章學到更多知識。更多詳情敬請關注億速云行業資訊頻道。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女