Adding additional data adapter parameters at run time

Posted on 2007-07-26
Last Modified: 2013-11-07
I'm working on a report form which just contains a data adapter and a listview.  The backend is Microsoft SQL server.  The SQL for the report is

SELECT        Contact.ContactID, Contact.ContactDisplayName, Contact.ContactAddressCSV, Contact.ContactAdviserID, Contact.ContactLocalAuthorityID,
                         Contact.ContactAgeGroupID, Contact.ContactSexID, Contact.ContactEmploymentStatusID, Contact.ContactEnquirySourceID, Contact.ContactDOB,
                         Contact.ContactEthnicity, Contact.ContactBHEOfficeID, Session.SessionDisplayName, Session.SessionSatisfactionID, Session.SessionLocation,
                         Session.SessionNotes, Session.SessionAdvisorID, Session.SessionType, Session.SessionPrice, Session.SessionBackground
FROM            Contact INNER JOIN
                         ContactSession ON Contact.ContactID = ContactSession.ContactSessionContactID INNER JOIN
                         Session ON ContactSession.ContactSessionSessionID = Session.SessionID
WHERE        (Session.SessionDate >= @FromSessionDate) AND (Session.SessionDate <= @ToSessionDate) AND (Session.SessionType = @SessionType) AND
                         (Contact.ContactLocalAuthorityID = @LocalAuthorityTypeID)

The parameters are specified at run time as the users pick options from drop downs and then click run and it then runs the above SQL code using a data adapter.  This works fine but there's one problem, the LocalAuthorityTypeID could be one of up to 50 choices.  So I need the ability to add additional OR statements to the data adapter that contains this SQL command text at run time.

Does anybody have any ideas of a way to go about the above?  OR even better still is there an easier way to achieve the above result?
Question by:noel58
    LVL 12

    Expert Comment

    Sorry not to understand. Do you want Contact.ContactLocalAuthorityID = @LocalAuthorityTypeID be changet to something as  @LocalAuthorityTypeID IN (<list of possible IDs>) ?
    Or you want to fill dropdown by walues from database?
    LVL 6

    Accepted Solution

    You could specify the Parameters of the SqlCommand. Have a look at this:

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
    This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now