'Program: Ch.04Lab 'Programmer: Joseph Schuman 'Date: September 2014 'Class: Form1 'Description: Display customer information and orders for the selected ' customer. This is the presentation tier, which uses the services ' of the data tier Imports System.Data Public Class Form1 'Module-level variables. Private ANorthwindDataTier As NorthwindDataTier Private ANorthWindDataSet As NorthwindDataSet Private CustomersBindingSource As BindingSource Private OrdersBindingSource As BindingSource Private Sub Form1_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Load Try ANorthwindDataTier = New NorthwindDataTier '*****This is the problem - it should be = ANorthwindDataTier.GetDataSet 'ANorthWindDataSet = New NorthwindDataSet ANorthWindDataSet = ANorthwindDataTier.GetDataSet 'Set up customers binding source. CustomersBindingSource = New BindingSource With CustomersBindingSource .DataSource = ANorthWindDataSet .DataMember = "Customers" .Sort = "CompanyName" End With 'Bind the form controls. With CompanyNameComboBox .DataSource = CustomersBindingSource .DisplayMember = "CompanyName" .ValueMember = "CustomerID" .DataBindings.Add("text", CustomersBindingSource, "CustomerID", False, _ DataSourceUpdateMode.Never) .SelectedIndex = -1 End With 'Set up the Orders binding source. OrdersBindingSource = New BindingSource With OrdersBindingSource .DataSource = ANorthWindDataSet .DataMember = "Orders" End With Catch ex As Exception MessageBox.Show("Error: " & ex.Message) End Try End Sub Private Sub CompanyNameComboBox_SelectionChangeCommitted( _ ByVal sender As Object, ByVal e As System.EventArgs) _ Handles CompanyNameComboBox.SelectionChangeCommitted 'Retrieve the customer information for the grid. Dim CustomerIDString As String Static GridInitializedBoolean As Boolean = False 'Retrieve the ID of the selected customer. CustomerIDString = CompanyNameComboBox.SelectedValue.ToString 'Initialize the grid's binding. If Not GridInitializedBoolean Then 'Bind the information from Customers table into the text boxes. CustomerIDTextBox.DataBindings.Add("text", CustomersBindingSource, _ "CustomerID", False, DataSourceUpdateMode.Never) ContactNameTextBox.DataBindings.Add("text", CustomersBindingSource, _ "ContactName", False, DataSourceUpdateMode.Never) ContactTitleTextBox.DataBindings.Add("text", CustomersBindingSource, _ "ContactTitle", False, DataSourceUpdateMode.Never) PhoneTextBox.DataBindings.Add("text", CustomersBindingSource, _ "Phone", False, DataSourceUpdateMode.Never) 'Clear text boxes for the first line. CustomerIDTextBox.Clear() ContactNameTextBox.Clear() ContactTitleTextBox.Clear() PhoneTextBox.Clear() 'Bind and format the grid. OrdersDataGridView.DataSource = OrdersBindingSource SetUpGridColumns() GridInitializedBoolean = True End If 'Filter the grid's data. '*****This is the other problem - you left out the 1st ' 'OrdersBindingSource.Filter = "CustomerID= " & CustomerIDString & "'" OrdersBindingSource.Filter = "CustomerID= '" & CustomerIDString & "'" End Sub Private Sub SetUpGridColumns() 'Set up the columns for the grid. Try With OrdersDataGridView .Columns!OrderID.HeaderText = "Order ID" .Columns!OrderDate.HeaderText = "Order Date" .Columns!RequiredDate.HeaderText = "Required Date" .Columns!ShippedDate.HeaderText = "Shipped Date" End With Catch ex As Exception MessageBox.Show("Error setting up the grid. " & ex.Message) End Try End Sub Private Sub ExitToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ExitToolStripMenuItem.Click 'Close the form. Me.Close() End Sub Private Sub OrdersDataGridView_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles OrdersDataGridView.CellContentClick End Sub End Class