📄 form1.vb
字号:
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
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
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents cboCompanies As System.Windows.Forms.ComboBox
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents txtName As System.Windows.Forms.TextBox
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents txtTitle As System.Windows.Forms.TextBox
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents txtPhone As System.Windows.Forms.TextBox
Friend WithEvents OdbcDataAdapter1 As System.Data.Odbc.OdbcDataAdapter
Friend WithEvents OdbcConnection1 As System.Data.Odbc.OdbcConnection
Friend WithEvents CustomersDS1 As ODBC_Data_Wizard.CustomersDS
Friend WithEvents OdbcSelectCommand1 As System.Data.Odbc.OdbcCommand
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.cboCompanies = New System.Windows.Forms.ComboBox
Me.CustomersDS1 = New ODBC_Data_Wizard.CustomersDS
Me.Label1 = New System.Windows.Forms.Label
Me.txtName = New System.Windows.Forms.TextBox
Me.Label2 = New System.Windows.Forms.Label
Me.txtTitle = New System.Windows.Forms.TextBox
Me.Label3 = New System.Windows.Forms.Label
Me.txtPhone = New System.Windows.Forms.TextBox
Me.OdbcDataAdapter1 = New System.Data.Odbc.OdbcDataAdapter
Me.OdbcSelectCommand1 = New System.Data.Odbc.OdbcCommand
Me.OdbcConnection1 = New System.Data.Odbc.OdbcConnection
CType(Me.CustomersDS1, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'cboCompanies
'
Me.cboCompanies.DataSource = Me.CustomersDS1.Customers_csv
Me.cboCompanies.DisplayMember = "CompanyName"
Me.cboCompanies.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
Me.cboCompanies.Location = New System.Drawing.Point(8, 8)
Me.cboCompanies.Name = "cboCompanies"
Me.cboCompanies.Size = New System.Drawing.Size(272, 21)
Me.cboCompanies.TabIndex = 0
Me.cboCompanies.ValueMember = "CustomerID"
'
'CustomersDS1
'
Me.CustomersDS1.DataSetName = "CustomersDS"
Me.CustomersDS1.Locale = New System.Globalization.CultureInfo("en-US")
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(8, 40)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(56, 16)
Me.Label1.TabIndex = 1
Me.Label1.Text = "Name"
Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight
'
'txtName
'
Me.txtName.Location = New System.Drawing.Point(72, 38)
Me.txtName.Name = "txtName"
Me.txtName.Size = New System.Drawing.Size(208, 20)
Me.txtName.TabIndex = 2
Me.txtName.Text = ""
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(8, 64)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(56, 16)
Me.Label2.TabIndex = 3
Me.Label2.Text = "Title"
Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight
'
'txtTitle
'
Me.txtTitle.Location = New System.Drawing.Point(72, 62)
Me.txtTitle.Name = "txtTitle"
Me.txtTitle.Size = New System.Drawing.Size(208, 20)
Me.txtTitle.TabIndex = 4
Me.txtTitle.Text = ""
'
'Label3
'
Me.Label3.Location = New System.Drawing.Point(8, 88)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(56, 16)
Me.Label3.TabIndex = 5
Me.Label3.Text = "Phone"
Me.Label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight
'
'txtPhone
'
Me.txtPhone.Location = New System.Drawing.Point(72, 86)
Me.txtPhone.Name = "txtPhone"
Me.txtPhone.TabIndex = 6
Me.txtPhone.Text = ""
'
'OdbcDataAdapter1
'
Me.OdbcDataAdapter1.SelectCommand = Me.OdbcSelectCommand1
Me.OdbcDataAdapter1.TableMappings.AddRange(New System.Data.Common.DataTableMapping() {New System.Data.Common.DataTableMapping("Table", "Customers_csv", New System.Data.Common.DataColumnMapping() {New System.Data.Common.DataColumnMapping("CustomerID", "CustomerID"), New System.Data.Common.DataColumnMapping("CompanyName", "CompanyName"), New System.Data.Common.DataColumnMapping("ContactName", "ContactName"), New System.Data.Common.DataColumnMapping("ContactTitle", "ContactTitle"), New System.Data.Common.DataColumnMapping("Phone", "Phone")})})
'
'OdbcSelectCommand1
'
Me.OdbcSelectCommand1.CommandText = "SELECT CustomerID, CompanyName, ContactName, ContactTitle, Phone FROM `Customers." & _
"csv` ORDER BY CompanyName"
Me.OdbcSelectCommand1.Connection = Me.OdbcConnection1
'
'OdbcConnection1
'
Me.OdbcConnection1.ConnectionString = "PageTimeout=5;MaxScanRows=8;DefaultDir=C:\DOCUMENTS AND SETTINGS\THEARON\MY DOCUM" & _
"ENTS\BEGINNING VB.NET DATABASES\CHAPTER 3\ODBC DATA WIZARD;FILEDSN=C:\Program Fi" & _
"les\Common Files\ODBC\Data Sources\ODBCText.dsn;DriverId=27;DBQ=C:\DOCUMENTS AND" & _
" SETTINGS\THEARON\MY DOCUMENTS\BEGINNING VB.NET DATABASES\CHAPTER 3\ODBC DATA WI" & _
"ZARD;UserCommitSync=Yes;FIL=text;UID=admin;Driver={Microsoft Text Driver (*.txt;" & _
" *.csv)};MaxBufferSize=2048;Threads=3;SafeTransactions=0"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 117)
Me.Controls.Add(Me.txtPhone)
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.txtTitle)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.txtName)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.cboCompanies)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
Me.MaximizeBox = False
Me.MinimizeBox = False
Me.Name = "Form1"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "ODBC Data Wizard"
CType(Me.CustomersDS1, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
OdbcDataAdapter1.Fill(CustomersDS1)
Call cboCompanies_SelectedIndexChanged(Nothing, Nothing)
End Sub
Private Sub cboCompanies_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboCompanies.SelectedIndexChanged
For intIndex As Integer = 0 To CustomersDS1.Tables( _
"Customers_csv").Rows.Count - 1
If CustomersDS1.Tables("Customers_csv").Rows(intIndex).Item( _
"CustomerID") = cboCompanies.SelectedValue Then
txtName.Text = CustomersDS1.Tables( _
"Customers_csv").Rows(intIndex).Item("ContactName")
txtTitle.Text = CustomersDS1.Tables( _
"Customers_csv").Rows(intIndex).Item("ContactTitle")
txtPhone.Text = CustomersDS1.Tables( _
"Customers_csv").Rows(intIndex).Item("Phone")
Exit For
End If
Next
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -