Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Select parameters ASP.NET

Posted on 2010-08-25
9
Medium Priority
?
337 Views
Last Modified: 2012-05-10
Hello folks,

I have a question, I am tryng to find a record by its name or last name,, I am using an Access Data Source and the following parameters , but the code is not working as I expect,,, If I use only the Name and a control parameter it does work, bu I need both .... how would I go about this? Thanks

Please see the query I am using
<asp:AccessDataSource ID="AccessDataSource2" runat="server" 
        DataFile="~/App_Data/Providers.accdb" 
        SelectCommand="SELECT [First_Name],[Last_Name],[Prof_Designation], [Specialty], [Specialty2],[Address], [Address2], [City], [State], [Zip], [Phone], [Fax], [lat], [lng] FROM [tbl_Providers] WHERE  
        (@First_Name IS NULL OR First_Name LIKE '%' +  @First_Name + '%') AND
        (@Last_Name IS NULL OR Last_Name LIKE '%' +  @Last_Name + '%') AND
        (@Specialty IS NULL OR Specialty LIKE '%' + @Specialty + '%') AND  
        (@Zip IS NULL OR Zip LIKE '%' + @Zip + '%')"
         CancelSelectOnNullParameter="False">
        <SelectParameters>

        <asp:ControlParameter ControlID="providerTextBox" Name="First_Name"  PropertyName ="Text" Type="String"  ConvertEmptyStringToNull ="true" />
        <asp:ControlParameter ControlID="providerTextBox" Name="Last_Name"  PropertyName ="Text" Type="String"  ConvertEmptyStringToNull ="true" />
        <asp:ControlParameter ControlID="specialityDropDown" Name="Specialty" PropertyName ="SelectedValue" Type="String" ConvertEmptyStringToNull ="true" />
        <asp:ControlParameter ControlID="txtZipCode" Name="Zip" PropertyName ="Text" Type="String" ConvertEmptyStringToNull ="true"  />

        
     </SelectParameters>

Open in new window

0
Comment
Question by:TonyReba
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
9 Comments
 
LVL 13

Expert Comment

by:Surone1
ID: 33522835
do you want to show a record if the firstname AND the lastname are correct?
or when the firstname OR the lastname is correct?
0
 
LVL 35

Expert Comment

by:YZlat
ID: 33523165
could you explain what exactly are you trying to do here?
0
 
LVL 35

Assisted Solution

by:YZlat
YZlat earned 800 total points
ID: 33523231
if you meant First and Last name together, then try:

<asp:AccessDataSource ID="AccessDataSource2" runat="server"
        DataFile="~/App_Data/Providers.accdb"
        SelectCommand="SELECT [First_Name],[Last_Name],[Prof_Designation], [Specialty], [Specialty2],[Address], [Address2], [City], [State], [Zip], [Phone], [Fax], [lat], [lng] FROM [tbl_Providers] WHERE  
        ((@First_Name IS NULL AND @Last_Name IS NULL) OR First_Name + ', ' + Last_Name LIKE '%' +  @First_Name + ', ' + @Last-Name + '%') AND
        (@Specialty IS NULL OR Specialty LIKE '%' + @Specialty + '%') AND  
        (@Zip IS NULL OR Zip LIKE '%' + @Zip + '%')"
         CancelSelectOnNullParameter="False">
        <SelectParameters>

        <asp:ControlParameter ControlID="providerTextBox" Name="First_Name"  PropertyName ="Text" Type="String"  ConvertEmptyStringToNull ="true" />
        <asp:ControlParameter ControlID="providerTextBox" Name="Last_Name"  PropertyName ="Text" Type="String"  ConvertEmptyStringToNull ="true" />
        <asp:ControlParameter ControlID="specialityDropDown" Name="Specialty" PropertyName ="SelectedValue" Type="String" ConvertEmptyStringToNull ="true" />
        <asp:ControlParameter ControlID="txtZipCode" Name="Zip" PropertyName ="Text" Type="String" ConvertEmptyStringToNull ="true"  />

       
     </SelectParameters>
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 9

Author Comment

by:TonyReba
ID: 33523574
I am trying to get the results for any part of a name  so whatever in providertextboxm matches ,,, First_Name, Last_Name need to query
0
 
LVL 13

Accepted Solution

by:
Surone1 earned 1200 total points
ID: 33523603
then you probably want to use OR instead of AND.
0
 
LVL 9

Author Comment

by:TonyReba
ID: 33523613
i get

No value given for one or more required parameters.
0
 
LVL 9

Author Comment

by:TonyReba
ID: 33523644
this actually did the trick
<asp:AccessDataSource ID="AccessDataSource2" runat="server" 
        DataFile="~/App_Data/Providers.accdb" 
        SelectCommand="SELECT [First_Name],[Last_Name],[Prof_Designation], [Specialty], [Specialty2],[Address], [Address2], [City], [State], [Zip], [Phone], [Fax], [lat], [lng] FROM [tbl_Providers] WHERE  
        ((@First_Name IS NULL OR First_Name LIKE '%' +  @First_Name + '%') OR
        (@Last_Name IS NULL OR Last_Name LIKE '%' +  @Last_Name + '%')) AND
        (@Specialty IS NULL OR Specialty LIKE '%' + @Specialty + '%') AND  
        (@Zip IS NULL OR Zip LIKE '%' + @Zip + '%')"
         CancelSelectOnNullParameter="False">
        <SelectParameters>

Open in new window

0
 
LVL 9

Author Closing Comment

by:TonyReba
ID: 33523654
thanks
0
 
LVL 13

Expert Comment

by:Surone1
ID: 33523663
our pleasure
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

609 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