sql - ASP.NET SqlDataSource, like on SelectCommand -
i'm working on asp.net. have sqldatasource
query hardcoded on selectcommand:
<asp:sqldatasource id="datasource1" runat="server" cancelselectonnullparameter="false" connectionstring="<%$ connectionstrings:s.properties.settings.connectionstring %>" selectcommand="select * [table] ([col1] case @col1_param when null col1 else @col1_param end) , ([col2] case @col2_param when null col2 else @col2_param end)" selectcommandtype="text"> <selectparameters> <asp:controlparameter controlid="textbox1" name="col1_param" propertyname="text" type="string" /> <asp:controlparameter controlid="textbox2" name="col2_param" propertyname="text" type="string" /> </selectparameters>
what want if enter data on 1 textbox only, data display according textbox value on clause. , if no values placed neither of textboxes, the query executes if there no where.
right code,what happens if put on 1 textbox no data displayed. same if textboxes empty.
i don't want use sql stored procedure.
how can solve this?
thanks...
assuming passes null when there no text entered, otherwise need check empty string
selectcommand="select * [table] ([col1] '%@col1_param%' or @col1_param null) , ([col2] '%@col2_param%' or @col2_param null)"
Comments
Post a Comment