Solved

Select parameters ASP.NET

Posted on 2010-08-25
9
332 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 200 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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
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 300 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

Increase Agility with Enabled Toolchains

Connect your existing build, deployment, management, monitoring, and collaboration platforms. From Puppet to Chef, HipChat to Slack, ServiceNow to JIRA, Splunk to New Relic and beyond, hand off data between systems to engage the right people.

Connect with xMatters.

Question has a verified solution.

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

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

691 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