Link to home
Start Free TrialLog in
Avatar of Juan Velasquez
Juan VelasquezFlag for United States of America

asked on

Creating a Dynamic TableAdapter

Hello,

I have the following form which use the following combo boxes to filter the dataversionid listbox
1. Filter by Budget Year
2. Filter by Input Code
3. Filter by Technology Set

I want to avoid creating nine different methods in  the underlying table adapter.  I would need to create nine getdata methods in order to take into account all possible selections of comboboxes that user may make selection from.  Below is the type of code I originally had in mind.  But it seems to me, there should be a better way.  Thanks
If cboBudgetYear.SelectedIndex > -1 Then
            Dim intSelectedYear As Integer = Convert.ToInt32(cboBudgetYear.Text.Substring(0, 4))
            Me.CommentsTableAdapter.FillByBY(Me.BADSDataSet.Comments, intSelectedYear)
            MessageBox.Show(intSelectedYear.ToString)
        Else
            Me.CommentsTableAdapter.Fill(Me.BADSDataSet.Comments)
            MessageBox.Show("No Budget Year Selected")

        End If

Open in new window

GraphDesigner.JPG
Avatar of Juan Velasquez
Juan Velasquez
Flag of United States of America image

ASKER

I just realized I can create a stored procedure to do what I want that has conditional statement to return the correct dataset
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hello Code Cruiser.  I went ahead and went the stored procedure route.  I created a procedure that takes the user selections as optional variables and via a series of conditional statements returns the correct set of records. I'll will use this stored procedure to filter the dataversionld listbox via the fill method of the underlying data adapter.  
That's great. Stored procedures are the best option in speed, performance, network traffic, and security aspects.