Solved

Select parameters ASP.NET

Posted on 2010-08-25
9
325 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
  • 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
 
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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

867 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

19 Experts available now in Live!

Get 1:1 Help Now