Creating a subset
-
For a Windows form using VB.NET and an Access database of community events. I have a DataAdaptor and DataSet that create a datatable with a row for each event. I also have a DataAdaptor and DataSet that create a datatable for sponsoring organizations. I would like to have a combo box to choose the organization (bound to the organization table) and then populate the event combo box with a list of events sponsored by that organization. The user would then choose the event and the rest of the form controls would fill with the information for that event. How would I create a subset of events based on the sponsoring organization? Do I create another DataAdaptor and DataSet through code to create an event table based on the organization chosen? The books I have describe how to create DataAdaptor and DataSets through code, but once created, is there a way to destroy them and create others based on choosing another sponsoring organization?
-
For a Windows form using VB.NET and an Access database of community events. I have a DataAdaptor and DataSet that create a datatable with a row for each event. I also have a DataAdaptor and DataSet that create a datatable for sponsoring organizations. I would like to have a combo box to choose the organization (bound to the organization table) and then populate the event combo box with a list of events sponsored by that organization. The user would then choose the event and the rest of the form controls would fill with the information for that event. How would I create a subset of events based on the sponsoring organization? Do I create another DataAdaptor and DataSet through code to create an event table based on the organization chosen? The books I have describe how to create DataAdaptor and DataSets through code, but once created, is there a way to destroy them and create others based on choosing another sponsoring organization?
Do u mean that u got 2 combobox, 1st lists organisations, 2nd lists events sponsored by selected organisation in 1st ComboBox? If so; I think u have two tables, one has organisations list, others has events then assume two table is related to each other with OrganisationID. 1. Warn = use Just ONE DATASET, if not, it s painful. ============================================================================
Imports System.Data.SqlClient Public Class frmOrganisationsAndEvents Inherits System.Windows.Forms.Form ' On Form There is two ComboBox named cmbOrganisations and cmbEvents Dim cnOE As New SqlConnection("") Dim dsOE As New DataSet Dim dRowOE() As DataRow Private Sub frmOrganisationsAndEvents_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim adpOE As New SqlDataAdapter("SELECT * FROM Organisations", cnOE) adpOE.Fill(dsOE, "Organisations") adpOE.SelectCommand.CommandText = "SELECT * FROM Events" adpOE.Fill(dsOE, "Events") For i As Short = 0 To dsOE.Tables("Organisations").Rows.Count - 1 cmbOrganisations.Items.Add(dsOE.Tables("Organisations").Rows(i)("O_OrganisationName")) Next If Not cmbOrganisations.Items.Count = 0 Then cmbOrganisations.Text = "Select an Organisation" Else cmbOrganisations.Text = "No Organisation Installed" End If End Sub Private Sub cmbOrganisations_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbOrganisations.SelectedIndexChanged If Not cmbOrganisations.Items.Count = 0 And cmbOrganisations.SelectedIndex = -1 Then cmbEvents.Items.Clear() **'Events SubSet** drowOE = dsOE.Tables("Events").Select("E_OrganisationID=" & dsOE.Tables("Organisations").Rows(cmbOrganisations.SelectedIndex)("O_OrganisationID")) If Not dRowOE.Length = 0 Then For i As Short = 0 To dRowOE.GetUpperBound(0) cmbEvents.Items.Add(dRowOE(i)("E_EventAlias")) Next cmbOrganisations.Text = "Select Event Sponsored by " & dsOE.Tables("Organisations").Rows(cmbOrganisations.SelectedIndex)("O_OrganisationName") Else cmbOrganisations.Text = "No Event Installed Sponsored by " & dsOE.Tables("Organisations").Rows(cmbOrganisations.SelectedIndex)("O_OrganisationName") End If End If End Sub Priv