Group,

I have a web application (ASP.NET VB) that has a Gridview attached to
a dynamic datasource.  The SelectCommand is dynamically genereated
with if/then logic based on a session variable value previously
obtained.

One query filters the results based on five selection perameters the
(one textbox - A.FIELD_LAST_NAME , 4 session variables - A.FIELD_CCTR,
A.FIELD_SUPV, A.FIELD_VP, A.FIELD_EVP )).
___________________________________________________________________________

SELECT DISTINCT A.FIELD_EMPLE, A.FIELD_EMPLE_STATUS,
A.FIELD_LAST_NAME, A.FIELD_FIRST_NAME, A.FIELD_MIDDLE_INIT,
A.FIELD_CCTR, A.FIELD_SUPV, A.FIELD_VP, A.FIELD_EVP, B.FIELD2_SIGNON,
B.FIELD2_APPL, B.FIELD2_INACT_DATE

FROM DB.TABLE1 A INNER JOIN DB.TABLE2 B ON B.FIELD2_SIGNON =
A.FIELD_EMPLE

WHERE (A.FIELD_CCTR = ? OR A.FIELD_SUPV = ? OR A.FIELD_VP = ? OR
A.FIELD_EVP =?) AND (A.FIELD_EMPLE_STATUS <> 'D') AND
(B.FIELD2_INACT_DATE = 'CRITERIA') AND (A.FIELD_LAST_NAME LIKE ?||'%')
AND (B.FIELD2_APPL_ID = 'CRITERIA1' OR B.FIELD2_APPL_ID =
'CRITERIA2')

ORDER BY A.FIELD_LAST_NAME, A.FIELD_FIRST_NAME ASC
___________________________________________________________________________

The other query is less filtered (only one textbox -
A.FIELD_LAST_NAME):
___________________________________________________________________________

SELECT DISTINCT A.FIELD_EMPLE, A.FIELD_EMPLE_STATUS,
A.FIELD_LAST_NAME, A.FIELD_FIRST_NAME, A.FIELD_MIDDLE_INIT,
A.FIELD_CCTR, A.FIELD_SUPV, A.FIELD_VP, A.FIELD_EVP, B.FIELD2_SIGNON,
B.FIELD2_APPL, B.FIELD2_INACT_DATE

FROM DB.TABLE1 A INNER JOIN DB.TABLE2 B ON B.FIELD2_SIGNON =
A.FIELD_EMPLE

WHERE (A.FIELD_LAST_NAME LIKE ?||'%')
___________________________________________________________________________


With the different WHERE Clauses, there are different
SelectParameters.  I am attempting to use the following syntax to add
the Select Parameters as needed :

Me.DataSrouce.SelectParameters.Add()

How do I generate different parameters based on the query selected?
The top query references session variables for the following:
(A.FIELD_CCTR = ? OR A.FIELD_SUPV = ? OR A.FIELD_VP = ? OR A.FIELD_EVP
=?)

The second query only references a textbox for the last name:
(A.FIELD_LAST_NAME LIKE ?||'%')

FYI... My If/then logic is below:

        If Label1.Text = "Y" Then
            Me.Gridview.SelectCommand = "TopQuery"
            Me.Gridview.DataBind()
        Else
            Me.Gridview.SelectCommand = "BottomQuery"
            Me.GridviewList.DataBind()
        End If

Reply via email to