c# - Sending null parameter to querystring Stored Procedure -


i have following problem. want send null value stored procedure querystringparameter.

this stored procedure

create procedure spgetallproducts  @catid int = null,  @subcatid int = null begin     select * products     ((@catid null) or (category_id = @catid))     , ((@subcatid null) or (subcategory_id = @subcatid)) end 

it working when testing following queries how want

spgetallproducts null, '3' spgetallproducts '8', null spgetallproducts '8', '3' spgetallproducts null, null 

but when trying send null value queryparameter not working

here sqldatasource

<asp:sqldatasource id="sqldatasource1" runat="server" connectionstring="<%$ connectionstrings:connectionstringreviewdb %>" selectcommandtype="storedprocedure" selectcommand="spgetallproducts">      <selectparameters>     <asp:querystringparameter direction="input" name="catid" querystringfield="catid" type="int32" />     <asp:querystringparameter direction="input" name="subcatid" querystringfield="subcatid" type="int32" defaultvalue="" convertemptystringtonull="true" />     </selectparameters>      </asp:sqldatasource> 

when sending query this

http://localhost:50693/treeviews.aspx?catid=8&subcatid=3 

it working when sending following query not working

http://localhost:50693/treeviews.aspx?catid=8&subcatid= 

thx now

try this

create procedure spgetallproducts @catid int = null, @subcatid int = null begin select * products ((@catid '') or (category_id = @catid)) , ((@subcatid = '') or (subcategory_id = @subcatid)) end

i think stored procedure takes empty string not null ,i had similar problem , worked me


Comments