form1.vb

来自「wrox出版社的另一套经典的VB2005数据库编程学习书籍,收集了书中源码,郑重」· VB 代码 · 共 53 行

VB
53
字号
Option Explicit On
Option Strict On
Imports System.Data
Imports System.Data.SqlClient

Public Class Form1
    'Autogenerated code
    Private Sub bindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        If Me.Validate Then
            Me.CustomersBindingSource.EndEdit()
            Me.CustomersTableAdapter.Update(Me.NorthwindDataSet.Customers)
        Else
            System.Windows.Forms.MessageBox.Show(Me, "Validation errors occurred.", "Save", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning)
        End If
    End Sub

    Private Sub FillByCustomerIDToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FillByCustomerIDToolStripButton.Click
        'Autogenerated code
        Try
            Me.CustomersTableAdapter.FillByCustomerID(Me.NorthwindDataSet.Customers, cboCustomerID.Text)
            Me.OrdersTableAdapter.FillByCustomerID(Me.NorthwindDataSet.Orders, cboCustomerID.Text)
            Me.Order_DetailsTableAdapter.FillByCustomerID(Me.NorthwindDataSet.Order_Details, cboCustomerID.Text)
        Catch ex As System.Exception
            System.Windows.Forms.MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Load the cbo CustomerID combo box
        Dim cnNwind As New SqlConnection(My.Settings.NorthwindConnectionString)
        Dim strSQL As String = "SELECT CustomerID FROM dbo.Customers"
        Dim cmNwind As New SqlCommand(strSQL, cnNwind)
        Try
            cnNwind.Open()
            Dim sdrCustID As SqlDataReader = cmNwind.ExecuteReader
            With sdrCustID
                If .HasRows Then
                    cboCustomerID.Items.Clear()
                    While .Read
                        cboCustomerID.Items.Add(sdrCustID(0).ToString)
                    End While
                    cboCustomerID.Text = cboCustomerID.Items(0).ToString
                End If
                .Close()
            End With
        Catch exc As Exception
            MsgBox("Error loading CustomerID combo box.")
        Finally
            cnNwind.Close()
        End Try
    End Sub
End Class

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?