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 6388041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:13:45+00:00 2026-05-25T03:13:45+00:00

The following SQL query WORKS perfectly in SQL Management Studio: DECLARE @phone AS varchar(25)

  • 0

The following SQL query WORKS perfectly in SQL Management Studio:

DECLARE @phone AS varchar(25)
SET     @phone = NULL 
DECLARE @firstname AS varchar(25)
SET     @firstname = NULL
DECLARE @lastname AS varchar(25)
SET     @lastname = NULL
DECLARE @email AS varchar(300)
SET     @email = NULL


 SELECT        id, lead_code, first_name + ' ' + last_name AS [name], lead_status, lead_source, date_entered, city, state, zip, gender, home_phone, call_back
  FROM            leads

 WHERE      (home_phone = @phone OR @phone IS NULL) AND
            (first_name = @firstname OR @firstname IS NULL) AND 
            (last_name = @lastname OR @lastname IS NULL) AND 
            (email = @email OR @email IS NULL)

ORDER BY date_entered DESC

Here’s the top of the sproc:

ALTER PROCEDURE dbo.custom_LeadsGetAllLeadsSimpleSearchParams
    (
        @phone varchar(25) = null,
        @firstname varchar(25) = null,
        @lastname varchar(25) = null,
        @email varchar(300) = null
    )
AS
 SELECT        id.....

Running it this way gives me all 2100 rows in my DB, when I change one of the SET commands to search for a name, or email address, it returns JUST those rows, I think my SQL is (while maybe not awesome) working.

The problem is in the .NET piece.

From a codebehind of the the page I’m doing this:

                sd.SelectCommandType = SqlDataSourceCommandType.StoredProcedure;
                sd.SelectCommand = "custom_LeadsGetAllLeadsSimpleSearchParams";

                sd.SelectParameters.Add("@phone", strPhone);
                sd.SelectParameters.Add("@firstname", strFirstName);
                sd.SelectParameters.Add("@lastname", strLastName);
                sd.SelectParameters.Add("@email", strEmail);
                gvLeads.DataBind();

the string variables are passed as null when null. When I watch the sd.SelectParameters collection in the debugger, I’m seeing the parameter value as null when and where needed. The problem is that when the databind occurs, the grid renders with no data. I just get the gridview no rows text that I have set. Ideas?

  • 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-05-25T03:13:46+00:00Added an answer on May 25, 2026 at 3:13 am

    Have you tried adding this parameter?

    CancelSelectOnNullParameter

    Like this:

    sd.CancelSelectOnNullParameter = false;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following which works in SQL Query Analyzer . select oh.* from
This concerns sql show queries. The following query below works the issue is it
In SQL Server 2008, the following query works fine: WITH T AS ( SELECT
The following sql query works fine on my development server running mysql 5, but
I have the following SQL Server 2008 query that works for all of my
I have the following SQL query and so far it works the way it
I have the following sql query for transforming data but is it possible to
I have the following SQL query: select expr1, operator, expr2, count(*) as c from
I have a following SQL QUERY: SELECT articles.name, articles.price, users.zipcode FROM articles INNER JOIN
I have the following Sql Query that returns the type of results that I

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.