偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

代碼講述VB.NET實(shí)現(xiàn)數(shù)據(jù)綁定

開發(fā) 后端
這里介紹VB.NET實(shí)現(xiàn)數(shù)據(jù)綁定,TextBox組件通過下列語句就可以把已經(jīng)得到的數(shù)據(jù)集"myDataSet"中的"books.bookid"字段值綁定到TextBox1的"Text"屬性上。

VB.NET還是比較常用的,于是我研究了一下VB.NET實(shí)現(xiàn)數(shù)據(jù)綁定,在這里拿出來和大家分享一下,希望對大家有用。以下介紹VB.NET實(shí)現(xiàn)數(shù)據(jù)綁定:

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

  1. Imports System.Drawing  
  2. Imports System.Windows.Forms  
  3. Imports System.ComponentModel  
  4. Imports System  
  5. Imports System.Data.OleDb  
  6. Imports System.Data  
  7.  
  8. Public Class Form1  
  9. Inherits Form  
  10.  
  11. Private WithEvents Button1 As Button  
  12. Private TextBox1 As TextBox  
  13. Private myDataSet As DataSet  
  14. Private components As System.ComponentModel.Container  
  15.  
  16. Public Sub New ( )  
  17. MyBase.New()  
  18. GetConnected ( )  
  19. InitializeComponent ( )  
  20. End Sub  
  21. '清除在程序中使用過的資源  
  22. Protected Overloads Overrides Sub Dispose ( ByVal disposing As Boolean )  
  23. If disposing Then  
  24. If Not ( components Is Nothing ) Then  
  25. components.Dispose ( )  
  26. End If  
  27. End If  
  28. MyBase.Dispose ( disposing )  
  29. End Sub  
  30. '打開數(shù)據(jù)表,返回?cái)?shù)據(jù)集  
  31. public Sub GetConnected ( )  
  32. '創(chuàng)建一個(gè) OleDbConnection  
  33. Dim strCon As String = " Provider = Microsoft.Jet.OLEDB.4.0; Data Source = ..\sample.mdb" 
  34. Dim myConn As OleDbConnection = new OleDbConnection ( )  
  35. myConn.ConnectionString = strCon 
  36.  
  37. Dim strCom As string = " SELECT * FROM books " 
  38. '創(chuàng)建一個(gè) DataSet  
  39. myDataSet = new DataSet( )  
  40.  
  41. myConn.Open ( )  
  42. '用 OleDbDataAdapter 得到一個(gè)數(shù)據(jù)集  
  43. Dim myCommand As OleDbDataAdapter = new OleDbDataAdapter ( strCom , myConn )  
  44. '把Dataset綁定books數(shù)據(jù)表  
  45. myCommand.Fill ( myDataSet , "books" )  
  46. '關(guān)閉此OleDbConnection  
  47. myConn.Close ( )  
  48.  
  49. End Sub  
  50. '初始化窗體中的組件  
  51. Private Sub InitializeComponent ( )  
  52. Me.Text = "對TextBox組件實(shí)現(xiàn)數(shù)據(jù)綁定!" 
  53. Me.Width = 400 
  54. Me.Height = 300 
  55.  
  56. Button1 = New Button ( )  
  57. TextBox1 = New TextBox ( )  
  58.  
  59. Button1.Left = 200 
  60. Button1.Top = 200 
  61. Button1.Width = 100 
  62. Button1.Height = 40 
  63. Button1.TabIndex = 0 
  64. Button1.Text = "數(shù)據(jù)綁定" 
  65.  
  66. TextBox1.Left = 200 
  67. TextBox1.Top = 30 
  68. TextBox1.Width = 150 
  69. TextBox1.Height = 40 
  70.  
  71. Me.Controls.Add ( Button1 )  
  72. Me.Controls.Add ( TextBox1 )  
  73.  
  74. End Sub  
  75.  
  76. Private Sub Button1_Click ( ByVal sender As Object , _  
  77. ByVal e As System.EventArgs ) Handles Button1.Click  
  78. TextBox1.DataBindings.Add ( New Binding ( "Text" , Me.myDataSet , "books.bookid" ) )  
  79. End Sub  
  80. End Class  
  81.  
  82. Module Module1  
  83. Sub Main ( )  
  84. Application.Run ( new Form1 ( ) )  
  85. End sub  
  86. End Module 

【編輯推薦】

  1. VB.NET編寫托盤程序經(jīng)驗(yàn)雜談
  2. 手把手指導(dǎo)VB.NET Socket編程
  3. 快速了解VB.NET可選參數(shù)
  4. 詳細(xì)介紹VB.NET MyClass
  5. 自己動手用代碼實(shí)現(xiàn)VB.NET ListView加載數(shù)據(jù)
責(zé)任編輯:佚名 來源: IT168
相關(guān)推薦

2009-10-23 13:22:25

VB.NET實(shí)現(xiàn)拖動圖

2009-10-14 17:08:44

VB.NET使用Fil

2009-10-16 13:26:53

VB.NET Exce

2009-10-21 10:45:50

VB.NET Quic

2009-10-15 11:11:08

VB.NET Text

2009-10-15 16:39:00

VB.NET讀取INI

2009-10-14 11:15:06

VB.NET Grou

2009-10-10 16:44:52

VB.NET開發(fā)控件

2009-10-13 17:03:55

VB.NET面向?qū)ο?/a>

2009-11-02 15:45:03

VB.NET IEnu

2009-10-12 16:39:59

OracleTransVB.NET使用

2009-10-19 08:55:22

VB.NET多重繼承

2009-10-16 09:35:24

VB.NET制作透明窗

2009-10-14 13:15:09

VB.NET數(shù)據(jù)綁定

2010-01-12 16:39:26

VB.NET數(shù)據(jù)綁定

2009-10-12 13:40:47

VB.NET Data

2009-10-26 18:11:47

VB.NET調(diào)用Exc

2009-10-21 18:28:48

VB.NET表間拖放

2009-10-22 09:20:46

VB.NET Proc

2009-10-27 11:39:03

VB.NET事件處理程
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號