Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Gridview NULL criteria not showing
Message
General information
Forum:
ASP.NET
Category:
Other
Environment versions
OS:
Windows XP SP2
Network:
Windows NT
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01498857
Message ID:
01500812
Views:
34
>>>>Naomi,
>>>>
>>>>I have finally gotten back to trying out your suggestion. I have integrated the code from the message you linked below into the "OnSelecting" attribute of the datasource in question as follows:
>>>>
>>>>
>>>> protected void SqlEquip_Selecting(object sender, SqlDataSourceCommandEventArgs e)
>>>>    {
>>>>
>>>>        SqlParameterCollection myCollection = (SqlParameterCollection)e.Command.Parameters;
>>>>
>>>>        IEnumerator ie = myCollection.GetEnumerator();
>>>>        string strSQL = string.Empty;
>>>>        while ((ie.MoveNext()))
>>>>        {
>>>>            SqlParameter param = (SqlParameter)ie.Current;
>>>>            string strValue = string.Empty;
>>>>            if (param.Value == null)
>>>>            {
>>>>                strValue = "NULL";
>>>>            }
>>>>            else
>>>>            {
>>>>                strValue = param.Value.ToString();
>>>>                strSQL += param.ParameterName.ToString() + "=" + strValue + "<BR />";
>>>>            }
>>>>
>>>>        }
>>>>
>>>>        Response.Write(strSQL.ToString()); 
>>>>    }   
>>>> 
>>>>
>>>>
>>>>
>>>>and the "parsed parameters" for the stored procedure have the following values:
>>>>
>>>>		@upsino=%<BR />@sub_name=%<BR />@co_equipno=%<BR />@serial_no=%<BR />
>>>>
>>>>
>>>>This still doesn't tell me why records with a NULL value in any one of the last three fields are excluded from the result set. The sql command that is run from the stored procedure is listed below in our earlier post.
>>>>
>>>>Thank you so much.
>>>>
>>>>
>>>>
>>>>>>Unfortunately I am running SQL Server Express 2008 R2.
>>>>>>
>>>>>Took me a bit while to find this thread
>>>>>
>>>>>How to get printed SQL command that was passed Thread #1370295 Message #1370295
>>>>>
>>>>>In this thread I give a link to an answer by limno as how to get the command passed to SQL Server using only .NET code (when you don't have Profiler).
>>>>>
>>>>>Hope this helps.
>>>
>>>Looks like every single parameter has gotten a value of '%'. What is supposed to be returned in this case? Try running the same now in SSMS using % for each parameter.
>>
>>
>>Okay,, now that makes sense. When I set % as the value for each parameter in SSMS I'm getting the same results as in ASP. So, in my ASP code I am setting the "DefaultValue" attribute for each of these parameters of the SqlDataSource equal to %.
>>
>>When I'm running this query in SSMS (and its working correctly), I am DECLARING the parameters like this
>>
>>declare @upsino varchar(7) = '%'
>>declare @sub_name varchar(50) = null
>>declare @co_equipno varchar(50)=null
>>declare @serial_no varchar(30)=null
>>
>>How to I properly do that in my ASP code? Do I do it in the ascx file or the code behind file? I have the source code for the SqlDataSource in an earlier post in this thread.
>>
>>I'm getting closer, thank you.
>
>One possibility in SP to do
>
>set @sub = nullif(@Sub,'%')
>
>add this for each parameter and then follow your initial logic. Alternatively, set correctly DefaultValue for each parameter in ASP.NET code.

Naomi,

Thank you, thank you, thank you - IT WORKED. The "nullif()" suggestion works and its exactly what I've been looking for.

Thank you for sticking with me to the end on this one. I know you don't have to.

Just curious though, for future reference, you said "alternatively, set correctly DefaultValue for each parameter in ASP.NET code. How do I set the "DefaultValue" parameter to NULL in my ASP code. I tried DefaultValue=null and DefaultValue="null" and DefaultValue="" and DefaultValue='' (2 apostrophes) ,, with no luck.

Thanks again for you great help.
Elgin Rogers
Epic Solutions
www.epicsolutions.net
Previous
Reply
Map
View

Click here to load this message in the networking platform