在SQL数据源的两个地方使用控件作为参数 [英] Using a control as a parameter in two places in an SQL data source

查看:55
本文介绍了在SQL数据源的两个地方使用控件作为参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的aspx页面上有一个SQL数据源,该数据源连接到数据库并正确地带回数据.我遇到的问题是我试图在aspx页面上使用控件来过滤数据,但是我需要在SQL"OR"语句中使用该控件.数据仅接收"OR"语句的第一个where条件.我还尝试合并Select语句并获得相同的结果.

我看了网上,却没有发现任何与我的情况有关的东西.有谁知道这可以做到吗?有谁知道如何完成这项任务,或者知道从哪里找到答案?

我提供了连接字符串的示例:

I have an SQL data source on my aspx page that connects to the database and brings back data correctly. The issue I''m having is I''m trying to use a control on the aspx page to filter the data but I need to use the control in an SQL "OR" statement. The data is only picking up the first where condition of the "OR" statement. I also tried to union the Select statements and got the same results.

I''ve looked online and haven''t found anything that pertains to my situation. Does anyone know if this can be done? Does anyone know how to accomplish this task or know where to find the answer?

I''ve included a sample of the connection string:

<asp:SqlDataSource ID="sdsFiles" runat="server"

        ConnectionString="<%$ ConnectionStrings:ConnectionString %>"

        ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>"

        SelectCommand="SELECT List.* FROM List WHERE (Name = ?) OR (Name LIKE '%Admin%') AND (Path LIKE '%' + ? + '\%')
                        ORDER BY Skipped"

        <SelectParameters>
            <asp:ControlParameter ControlID="lblUName" Name="?" PropertyName="Text" />
        </SelectParameters>



我也尝试过:



I also tried:

<asp:SqlDataSource ID="sdsFiles" runat="server"

        ConnectionString="<%$ ConnectionStrings:ConnectionString %>"

        ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>"

        SelectCommand="SELECT List.* FROM List WHERE (Name = ?)
        Union
         SELECT List.* FROM List WHERE (Name LIKE '%Admin%') AND (Path LIKE '%' + ? + '\%')
                        ORDER BY Skipped"

        <SelectParameters>
            <asp:ControlParameter ControlID="lblUName" Name="?" PropertyName="Text" />
        </SelectParameters>



两者都给我相同的结果,因为它们只带回第一个where条件的结果.

谢谢,

Carolyn



Both give me the same results in that they only bring back the results for the first where condition.

Thanks,

Carolyn

推荐答案

ConnectionStrings:ConnectionString %> " ProviderName =" <%
ConnectionStrings:ConnectionString %>" ProviderName="<%


ConnectionStrings:ConnectionString.ProviderName %> " SelectCommand =" < SelectParameters > < asp:ControlParameter ControlID =" 名称 ? " PropertyName 文本" / < /SelectParameters >
ConnectionStrings:ConnectionString.ProviderName %>" SelectCommand="SELECT List.* FROM List WHERE (Name = ?) OR (Name LIKE '%Admin%') AND (Path LIKE '%' + ? + '\%') ORDER BY Skipped" <SelectParameters> <asp:ControlParameter ControlID="lblUName" Name="?" PropertyName="Text" /> </SelectParameters>



我也尝试过:



I also tried:

<asp:SqlDataSource ID="sdsFiles" runat="server"

        ConnectionString="<%


ConnectionStrings:ConnectionString %> ; " ProviderName =" <%
ConnectionStrings:ConnectionString %>" ProviderName="<%


这篇关于在SQL数据源的两个地方使用控件作为参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆