Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7969515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:14:55+00:00 2026-06-04T07:14:55+00:00

I’ve got a really weird problem and I can’t seem to find a solution

  • 0

I’ve got a really weird problem and I can’t seem to find a solution to it. I’ve got an SqlDataSource with a set of parameters and a select command in form of a stored procedure. One of the parameters is a string called @SearchPhrase which gets its value from a textbox that when left empty is suppose to return all posts. The parameter gets its value via a search button that first set the value of searchBox.Text.Trim() to the @SearchPhrase and then databinds a gridview that displays the search result.

The stored procedure works fine and returns the result as long as a value is entered in the textbox but when left empty it turns out the stored procedure is never executed. I know this because I’ve added a line to it that stores all of the parameters inserted every time it’s called.

How come I can’t get it to run without entering something in the textbox? The only way I can get it to execute is to enter a blank space and pass ” ” to the stored procedure and after that do a left and right trim on it. Why not when passing a string with length = 0?

Here’s the code for the datasource and the assigning of the parameters. It’s only the @SearchPhrase parameter that is causing the problem, the rest work just fine. The first three lines of the click event (the commented) is the somewhat ugly way to go if I want to assign a ” ” and that way make it work.

        <asp:SqlDataSource ID="enterprisesDS" runat="server" 
            ConnectionString="<%$ ConnectionStrings:CRMdb %>" 
            SelectCommand="entGetEnterprises" SelectCommandType="StoredProcedure">

            <SelectParameters>
                <asp:Parameter Name="SearchPhrase" Type="String" />
                <asp:Parameter Name="IsActive" Type="Boolean" DefaultValue="true" />
                <asp:Parameter Name="Country" Type="Byte" />
                <asp:Parameter Name="LocalReference" Type="String" />
                <asp:Parameter Name="Class" Type="String" />
                <asp:Parameter Name="LocationID" Type="Byte" />
            </SelectParameters>

        </asp:SqlDataSource>

        protected void search_Click(object sender, EventArgs e)
    {
        //string searchPhrase = " ";

        //if (searchBox.Text.Trim().Length > 0)
        //    searchPhrase = searchBox.Text.Trim();

        enterprisesDS.SelectParameters["SearchPhrase"].DefaultValue = searchBox.Text;
        enterprisesDS.SelectParameters["Country"].DefaultValue = countries.SelectedValue;
        enterprisesDS.SelectParameters["LocalReference"].DefaultValue = localReferences.SelectedValue;
        enterprisesDS.SelectParameters["Class"].DefaultValue = classes.SelectedValue;

        string locID = "0";
        if (locations.SelectedValue != null)
            locID = locations.SelectedValue;

        enterprisesDS.SelectParameters["LocationID"].DefaultValue = locID;

        enterprises.DataBind();
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T07:14:56+00:00Added an answer on June 4, 2026 at 7:14 am

    Could this be it? CancelSelectOnNullParameter property on the SqlDataSource.

    SqlDataSource and stored procedure call issue

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
i got an object with contents of html markup in it, for example: string
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
I am currently running into a problem where an element is coming back from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.