We help IT Professionals succeed at work.
Get Started

Populate combo box with filtered data (SQL Tabls) before main query runs

583 Views
Last Modified: 2012-08-18
Hi Experts.

I have a windows form that pulls data into a gridview based on a few controls.

There are from and to dates and a CheckListBox that determin which Shafts should be included in the gridview, the last filter is a combobox "CbxTeamLeader". what I need to do is once the Shafts Get selected in the checkbox ONLY the teams specific to the shafts must populate the combo box then based on that selection, the gridview gets updated

The Original Code looks like this (Thank you Ark for making this possible so far)
Dim dt As New DataTable
Dim strSQL As String = "SELECT * FROM Performance WHERE [Date] BETWEEN @DateFrom AND @DateTo"
Dim lstFilters As New List(Of String)
For Each s As String In ClbShaftSelect.CheckedItems
     lstFilters.Add(String.Format("(Shaft='{0}')", s))
Next
If lstFilters.Count > 0 Then
    strSQL += " AND (" & String.Join(" OR ", lstFilters.ToArray) & ")"
End If
If CbxTeamLeader.SelectedIndex > 0 Then 'or
'If  CbxTeamLeader.Text<>"" Then
    strSQL += " AND (TeamLeader='" & CbxTeamLeader.Text & "')"
End If

       Using conn As New SqlClient.SqlConnection(connString)
            conn.Open()
            Using da As New SqlClient.SqlDataAdapter(strSQL, conn)
                da.SelectCommand.Parameters.AddWithValue("@DateFrom", dateFrom)
                da.SelectCommand.Parameters.AddWithValue("@DateTo", dateTo)
                da.Fill(dt)
            End Using
            conn.Close()
        End Using

Return dt

Open in new window

Comment
Watch Question
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 1 Answer and 37 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE